[claude] Exclude /api paths from tower SPA fallback (#36) #81

Merged
claude merged 1 commits from claude/issue-36 into main 2026-03-23 02:14:51 +00:00

View File

@@ -79,7 +79,15 @@ const towerDist = (() => {
return path.join(process.cwd(), "the-matrix", "dist");
})();
app.use("/tower", express.static(towerDist));
app.get("/tower/*splat", (_req, res) => res.sendFile(path.join(towerDist, "index.html")));
app.get("/tower/*splat", (req, res, next) => {
// Never serve the SPA shell for requests that should hit the API or WS endpoint.
// The *splat wildcard would otherwise swallow paths like /tower/api/ws and return
// index.html, preventing the WebSocket upgrade from reaching the ws server.
const splatArr = (req.params as Record<string, string[]>)["splat"] ?? [];
const sub = splatArr.join("/");
if (sub === "api" || sub.startsWith("api/")) return next();
res.sendFile(path.join(towerDist, "index.html"));
});
// Vite builds asset references as absolute /assets/... paths.
// Mirror them at the root so the browser can load them from /tower.