Properly return 404 when the file does not exist #966
|
@ -69,10 +69,15 @@ http {
|
|||
ssl_certificate /etc/nginx/ssl/dummy.crt;
|
||||
ssl_certificate_key /etc/nginx/ssl/dummy.key;
|
||||
|
||||
location ~* .(txt|webmanifest|css|js|mjs|map|svg|jpg|jpeg|png|ico|ttf|woff|woff2|wav)$ {
|
||||
root /usr/share/nginx/html;
|
||||
try_files $uri $uri/ =404;
|
||||
|
||||
}
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
try_files $uri $uri/ /;
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ /index.html;
|
||||
index index.html;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
|
|
Reference in New Issue
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: