css issue
This commit is contained in:
@@ -47,6 +47,12 @@ function mountApp(base) {
|
||||
|
||||
if (serveStatic) {
|
||||
app.use(prefix || '/', express.static(distDir));
|
||||
// SPA fallback only for the app's base path, not root-level unknown files
|
||||
app.get(`${prefix}/*`, (req, res, next) => {
|
||||
const ext = req.path.split('.').pop();
|
||||
if (ext && ext !== req.path) return next();
|
||||
res.sendFile(path.join(distDir, 'index.html'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +63,15 @@ if (SITE_BASE) {
|
||||
mountApp(SITE_BASE);
|
||||
}
|
||||
|
||||
// Return proper 404 for missing static assets (prevents index.html served as JS/CSS)
|
||||
app.use((req, res, next) => {
|
||||
const ext = req.path.split('.').pop();
|
||||
if (ext && ext !== req.path) {
|
||||
return res.status(404).json({ error: 'Not found' });
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
app.use((err, _req, res, _next) => {
|
||||
if (err instanceof multer.MulterError && err.code === 'LIMIT_FILE_SIZE') {
|
||||
return res.status(413).json({ error: 'File too large (max 50MB)', code: 'FILE_TOO_LARGE' });
|
||||
|
||||
Reference in New Issue
Block a user