mirror of
https://github.com/sakaljurgis/best-choice.git
synced 2026-07-08 21:47:40 +00:00
Fix SPA fallback route for Express 5
This commit is contained in:
+5
-2
@@ -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));
|
||||||
app.get('*', (req, res, next) => {
|
const spaHandler = (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,10 @@ 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}".`
|
||||||
|
|||||||
Reference in New Issue
Block a user