web: an unknown path redirects to the root instead of serving a shell that cannot load

The app routes behind the hash (/#/plan, /#/history …), so a path is never a
screen, and the shell's asset URLs are relative (vite base './' — the Pages demo
lives under /demo/). nginx's SPA fallback served index.html AT the requested
path: for /plan/r/x (a typo, a stale link, anything not a file) the page's
scripts resolved to /plan/r/assets/… and 404'd — a blank page with a 200.

try_files now ends in a named location that answers 302 / (query string kept;
the hash never reaches the server). absolute_redirect off keeps the Location
relative, so the redirect stays on whatever scheme and host the reverse proxy
in front presented instead of nginx's own http://host:80. Files, directories,
/api/ and the regex locations are untouched.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit e49f1326e2c2c63c6688dfe85fc3e4bdd444231f)
This commit is contained in:
Boris Kurktchiev committed 2026-09-12 19:39:13 -04:00
1 parent d7f0f0dbdb
commit e77be0ac3f
1 file changed
+11 -2
+11 -2
View File
@@ -53,9 +53,18 @@ server {
proxy_set_header CF-Connecting-IP "${CF_CONNECTING_IP}";
}
# SPA fallback
# The app routes behind the hash (/#/plan, /#/history …), so a path is never a screen, and the
# shell's asset URLs are relative (vite base './' — the Pages demo lives under /demo/). Serving
# index.html AT a deep path (/plan/r/x: a typo, a stale link) gave a page whose scripts resolved
# under that path and 404'd — blank, with a 200. Send the browser to the root instead. The
# query string travels along; the hash never reaches the server anyway. Relative Location so
# the redirect keeps the scheme and host the reverse proxy in front presented, not nginx's own.
location / {
try_files $uri $uri/ /index.html;
try_files $uri $uri/ @root;
}
location @root {
absolute_redirect off;
return 302 /$is_args$args;
}
# App shell: always revalidate so updates show up immediately