Use middleware fallback for SPA routing

This commit is contained in:
Jurgis Sakalauskas
2025-11-14 10:37:32 +02:00
parent c084e3261c
commit eae6e08053
+2 -5
View File
@@ -16,7 +16,7 @@ if (env.client.serve) {
if (fs.existsSync(clientDistPath) && fs.existsSync(indexHtmlPath)) { if (fs.existsSync(clientDistPath) && fs.existsSync(indexHtmlPath)) {
app.use(express.static(clientDistPath)); app.use(express.static(clientDistPath));
const spaHandler = (req: express.Request, res: express.Response, next: express.NextFunction) => { app.use((req, res, next) => {
if (req.method !== 'GET' && req.method !== 'HEAD') { if (req.method !== 'GET' && req.method !== 'HEAD') {
return next(); return next();
} }
@@ -34,10 +34,7 @@ if (env.client.serve) {
} }
return res.sendFile(indexHtmlPath); return res.sendFile(indexHtmlPath);
}; });
app.get('/*', spaHandler);
app.head('/*', spaHandler);
} else { } else {
console.warn( console.warn(
`Static client assets not served because the build output was not found at "${clientDistPath}".` `Static client assets not served because the build output was not found at "${clientDistPath}".`