-
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
Conversation
Visit the preview URL for this PR (updated for commit 6942379): https://qa-ccv-brown-edu--pr105-debug-404-4x87pxyy.web.app (expires Tue, 05 Jul 2022 04:47:16 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
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.
This looks good to me! Couple of style comments, but nothing that should prevent a merge!
} | ||
else{ |
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 stick this on one line, not that it matters though...
@@ -11,6 +11,8 @@ let isReady = false; | |||
|
|||
let nuxt = loadNuxt('start'); | |||
|
|||
let dynamicRoutes = ['/_ghapi/status', '/_workday/opportunities'] |
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
res.set('X-Cascade', 'PASS') | ||
res.status(404).redirect('/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 think y'all might need a style enforcer like prettier
or standard
I'm seeing ;
sometimes, but not others
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.
Probably… we have it in the parent dir… may just need to add it to the functions dir..
// eslint-disable-next-line no-console | ||
console.log('GH Response') | ||
console.log(response); |
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.
You can probably delete this now
await nuxt.server.app.handle(req, res); | ||
} | ||
else{ | ||
console.log('Redirect to 404 page'); |
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.
Do you need this log still?
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.
Probably not
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.
Thanks you for tackling this weird problem! I didn't realize how weirdly nuxt handles 404! Great learnings in here and thank you for documenting them as well as instructions for updates.
I made comments on some typos. And then Brad also mentioned changes as well. Looking very good Isabel! Thanks again!
Co-authored-by: Ellen Duong <[email protected]>
This one was a bit tricky to figure out so I want to write out what I learned. The solution may not be perfect or the best, but it's the one way I got it to work. The issue arise from the combination of the way Nuxt handles 404, and the fact that our website is not fully static
Options for handling 404 page
If our site was fully static
We would need Firebase to redirect to a 404.html. To accomplish this one, would need to tell Nuxt to generate the
404.html
page in the config (we do that) by adding to the nuxt config file:and to add
"destination": "/404.html"
to the firebase config. We tried the followingAt first we thought that worked, but then realized that adding
"destination": "/404.html"
overshadows the function and the dynamic routes never get hitLinks
Final solution.
The solution is a bit inspired by this post. More specifically by these comments:
To make things more explicit.
/dist
) folder, then the cloud function is called. This is handled by firebase (config -"function": "ssrapp",
)404.html
If we don't do this and let Nuxt handle the non existing route, we get a 500 instead of 404, and the website becomes unresponsive unless refreshed. I think this is because Nuxt my not treat 404 as an error and therefore our
try/catch
doesn't handle it appropriately