-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle 404 on cloud functions #105
Changes from all commits
cf9f7cf
4cf371a
a5515ec
54c8b28
5eb5386
4532e6f
ffec53d
705c206
bd4a1fa
4e941dd
4f77a99
b2f0597
31f1a76
c0c05f6
0cfa1fa
6942379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ let isReady = false; | |
|
||
let nuxt = loadNuxt('start'); | ||
|
||
let dynamicRoutes = ['/_ghapi/status', '/_workday/opportunities'] | ||
|
||
async function handleRequest(req, res) { | ||
try { | ||
if (!isReady) { | ||
|
@@ -19,11 +21,19 @@ async function handleRequest(req, res) { | |
} | ||
console.log(req.path); | ||
res.set('Cache-Control', 'public, max-age=3600, s-maxage=7200'); | ||
await nuxt.server.app.handle(req, res, (out) => console.log(out)); | ||
if(dynamicRoutes.includes(req.path)){ | ||
await nuxt.server.app.handle(req, res); | ||
} | ||
else{ | ||
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd stick this on one line, not that it matters though... |
||
console.log('Redirect to 404 page'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this log still? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not |
||
res.set('X-Cascade', 'PASS') | ||
res.status(404).redirect('/404.html') | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think y'all might need a style enforcer like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably… we have it in the parent dir… may just need to add it to the functions dir.. |
||
} | ||
|
||
} catch (error) { | ||
console.log(error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
exports.ssrapp = functions.https.onRequest(handleRequest); | ||
exports.ssrapp = functions.https.onRequest(handleRequest); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,7 @@ export default { | |
await addSearch(nuxt); | ||
}, | ||
}, | ||
generate: { | ||
fallback: "404.html" | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider renaming this to whitelistedRoutes, that way we know that these routes are allowed by the cloud function. It's the normal language used for this sort of thing in networking. Obviously this doesn't matter either ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t love the whitel/black list terminology, but I could use allowedRoutes or something more clear