fix: use relative Vite base; serve SPA at both /v2/ and /clawstor/

Vite base: '/clawstor/' caused 404s when the SPA was served at /v2/
because asset paths like /clawstor/assets/... didn't match the actual
serve path /v2/assets/...

- vite.config.ts: switch to base: './' (relative paths work from any
  mount point — /v2/, /clawstor/, or bare /)
- serve.rs: mount the SPA at both /v2/ and /clawstor/; add 308 redirect
  from /v2 and /clawstor (no trailing slash) to their canonical forms
  so browsers don't misinterpret the last segment as a filename and
  break relative ./assets/ resolution

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
Omar Sobh
2026-07-23 19:45:55 +00:00
co-authored by Claude Sonnet 4.6
parent a8f0aa911c
commit 5001ac233c
3 changed files with 24 additions and 14 deletions
+17 -6
View File
@@ -719,12 +719,23 @@ pub fn build_app_with_v2(
v2_router = v2_router.merge(crate::serve_v2::build(v2s)); v2_router = v2_router.merge(crate::serve_v2::build(v2s));
} }
if let Some(dir) = v2_static_dir { if let Some(dir) = v2_static_dir {
v2_router = v2_router.nest_service( // Redirect bare paths (no trailing slash) to their canonical
"/v2", // slash-terminated form. Without this, browsers treat the path
tower_http::services::ServeDir::new(&dir).fallback( // segment as a file and resolve relative asset paths one level
tower_http::services::ServeFile::new(dir.join("index.html")), // too high, producing 404s for `./assets/…`.
), let redirect_v2 = get(|| async {
); axum::response::Redirect::permanent("/v2/")
});
let redirect_clawstor = get(|| async {
axum::response::Redirect::permanent("/clawstor/")
});
let spa = tower_http::services::ServeDir::new(&dir)
.fallback(tower_http::services::ServeFile::new(dir.join("index.html")));
v2_router = v2_router
.route("/v2", redirect_v2)
.route("/clawstor", redirect_clawstor)
.nest_service("/v2/", spa.clone())
.nest_service("/clawstor/", spa);
} }
Router::new() Router::new()
+1 -1
View File
@@ -1 +1 @@
{"root":["./src/app.tsx","./src/main.tsx","./src/components/nodecard.tsx","./src/components/projectspanel.tsx","./src/components/stattile.tsx","./src/components/storagebar.tsx","./src/lib/api.ts","./src/pages/commandcenter.tsx","./src/pages/nodedetail.tsx","./src/pages/reftrackingpage.tsx","./src/pages/storagebrowser.tsx"],"version":"6.0.3"} {"root":["./src/App.tsx","./src/main.tsx","./src/components/NodeCard.tsx","./src/components/NodeHistorySparklines.tsx","./src/components/ProjectsPanel.tsx","./src/components/StatTile.tsx","./src/components/StorageBar.tsx","./src/lib/api.ts","./src/pages/CommandCenter.tsx","./src/pages/NodeDetail.tsx","./src/pages/RefTrackingPage.tsx","./src/pages/StorageBrowser.tsx"],"version":"6.0.3"}
+6 -7
View File
@@ -6,13 +6,12 @@ import react from '@vitejs/plugin-react';
// During local dev the daemon proxies /api/v2/* on :7700 so // During local dev the daemon proxies /api/v2/* on :7700 so
// `vite dev` on :5173 can hit it via server.proxy. // `vite dev` on :5173 can hit it via server.proxy.
export default defineConfig({ export default defineConfig({
// Absolute base tied to the deploy path. Prior try was `./` // Relative base so the SPA works under any mount point (/v2/,
// (fully relative) which broke when the user hit `/clawstor` // /clawstor/, or bare /). The no-trailing-slash edge case
// without trailing slash — browser resolves `./assets/…` // (browser treats the path as a file and strips the last segment)
// against `/clawstor` treated as a file, gives `/assets/…`, // is handled server-side: serve.rs redirects /v2 → /v2/ and
// 404 from Tailscale. Absolute `/clawstor/` sidesteps the // /clawstor → /clawstor/ before serving the SPA.
// slash / no-slash ambiguity. base: './',
base: '/clawstor/',
plugins: [react()], plugins: [react()],
server: { server: {
port: 5173, port: 5173,