core: static sites serve a nested directory's index.html

`try_files {path} {path}/index.html /index.html` for SPA sites and the
dashboard: a URL like /docs/setup/ serves that directory's own index.html
before falling back to the root one, so a multi-page static site works at its
sub-paths while single-page apps still get client-side routing.

Found uncommitted in the checkout, author unknown, and already live: wildpc
runs from this tree, so every Caddyfile generated since used it.
This commit is contained in:
2026-10-23 15:19:33 -07:00
parent 959a896115
commit c6c361e38a
3 changed files with 15 additions and 11 deletions

View File

@@ -213,15 +213,16 @@ The build is run with `VITE_BASE=/`, so a `vite.config` that reads it (see
@host_my_frontend host my-frontend.example.com
handle @host_my_frontend {
root * /data/repos/my-frontend/dist
try_files {path} /index.html
try_files {path} {path}/index.html /index.html
file_server
}
```
The `try_files {path} /index.html` directive is essential for SPA routing —
it falls back to `index.html` for any path that doesn't match a static file,
letting React Router handle client-side routes. The subdomain is the program name,
not hand-configured.
The `try_files {path} {path}/index.html /index.html` directive handles both SPA
routing and multi-page static sites: it serves a matched static file, then a
nested directory's own `index.html` (so `/sub/dir/` URLs work), and otherwise
falls back to the root `index.html` for any unmatched path — letting React Router
handle client-side routes. The subdomain is the program name, not hand-configured.
## API integration