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.