File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff 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." ) ;
You can’t perform that action at this time.
0 commit comments