From c084e3261cfd9ad91116b4ce86e11c26e2d839ff Mon Sep 17 00:00:00 2001 From: Jurgis Sakalauskas Date: Fri, 14 Nov 2025 10:35:23 +0200 Subject: [PATCH] Fix SPA fallback route for Express 5 --- server/src/app.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/src/app.ts b/server/src/app.ts index b18bd5d..87341a5 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -16,7 +16,7 @@ if (env.client.serve) { if (fs.existsSync(clientDistPath) && fs.existsSync(indexHtmlPath)) { app.use(express.static(clientDistPath)); - app.get('*', (req, res, next) => { + const spaHandler = (req: express.Request, res: express.Response, next: express.NextFunction) => { if (req.method !== 'GET' && req.method !== 'HEAD') { return next(); } @@ -34,7 +34,10 @@ if (env.client.serve) { } return res.sendFile(indexHtmlPath); - }); + }; + + app.get('/*', spaHandler); + app.head('/*', spaHandler); } else { console.warn( `Static client assets not served because the build output was not found at "${clientDistPath}".`