From 04398e88e00fd59e50e9a88d5442f99b0b72fadd Mon Sep 17 00:00:00 2001 From: "Claude (Opus 4.6)" Date: Mon, 23 Mar 2026 02:14:49 +0000 Subject: [PATCH] [claude] Exclude /api paths from tower SPA fallback (#36) (#81) --- artifacts/api-server/src/app.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/artifacts/api-server/src/app.ts b/artifacts/api-server/src/app.ts index d415685..82f2a4b 100644 --- a/artifacts/api-server/src/app.ts +++ b/artifacts/api-server/src/app.ts @@ -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)["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.