Skip to content

Commit 882f5a7

Browse files
committed
server: only serve index.html for HTML GETs; exclude /api and /__diag
1 parent 311226e commit 882f5a7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ if (fs.existsSync(staticPath)) {
5050

5151
app.use(express.static(staticPath));
5252

53-
// SPA fallback: any non-API route should return index.html so the client-side router can handle it
53+
// SPA fallback: only serve index.html for GET requests that accept HTML,
54+
// and explicitly exclude API and diagnostic routes so API clients get JSON.
5455
app.get("/*", (req: Request, res: Response, next: NextFunction) => {
55-
if (req.path.startsWith("/api/")) return next();
56+
if (req.method !== "GET") return next();
57+
if (req.path.startsWith("/api/") || req.path.startsWith("/__diag")) return next();
58+
59+
const acceptHeader = req.headers.accept;
60+
const acceptsHtml =
61+
typeof acceptHeader === "string" && acceptHeader.indexOf("text/html") !== -1;
62+
if (!acceptsHtml) return next();
63+
5664
if (fs.existsSync(FRONTEND_INDEX)) return res.sendFile(FRONTEND_INDEX);
5765
// If index.html is missing respond with a small diagnostic message
5866
return res.status(500).send("Frontend index.html missing in image. Check server logs for details.");

0 commit comments

Comments
 (0)