mirror of
https://github.com/sakaljurgis/best-choice.git
synced 2026-07-08 21:47:40 +00:00
Use middleware fallback for SPA routing
This commit is contained in:
+2
-5
@@ -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}".`
|
||||||
|
|||||||
Reference in New Issue
Block a user