Properly return 404 when the file does not exist #966
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#966
Loading…
Reference in New Issue
No description provided.
Delete Branch "LordGaav/frontend:feature/do-not-return-200-on-every-request"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Nginx does not properly return a 404 code when a file does not exist, causing the service worker and/or browser caching to get confused at times. See my comment on this issue for details:
vikunja/api#966 (comment)
@ -72,3 +72,3 @@
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /;
try_files $uri $uri/ =404;
Unfortunately this breaks accessing something like
/login
(or password reset routes, share links etc) directly without going through/
.I see, you're right. Unfortunately, when serving with Nginx, the problem that I mentioned in the opening exists (serving 200 OK when actually it should be 404 Not Found).
Is there a way to generate static HTML files for the routes that we need?
Maybe, kind of. You could theoretically parse route definitions at
router/index.js
to figure out a regex map of all routes that are actually required and then put that in the nginx config. But then we might as well think about SSR...Maybe we're going about this wrong; we want to avoid returning 200 OK on .js files because that breaks the service worker, any other route doesn't really matter.
mhhhhh nginx can do regex, I'm sure we could modify the
location
block to do thetry_files
only work on files that are not ending on.js
. Then add another one to keep serving.js
files.Indeed, see my latest commit. I applied this to my own installation, and everything still seems to work.
Looks good.
Seems error-prone to list the files individually. E.g.
mp3
is missing.I did not actually find any mp3 files in the deployed Docker container, this list is all the extensions that I did find.
@dpschen do you know a way to generate that list?
I know that it's possible to prerender which also generates the routes that are static: https://vite-plugin-ssr.com/pre-rendering
Not sure if that helps though.
Regarding the list: I found this after a built in the dist folder using this:
Seems to work, will merge once the CI passes.
👌