don't redirect on 404 in build

This commit is contained in:
Cory LaViska
2024-12-05 16:34:07 -05:00
parent 8d93a44566
commit 32ed169ca8

View File

@@ -288,12 +288,18 @@ if (isDeveloping) {
callbacks: {
ready: (_err, instance) => {
// 404 errors
instance.addMiddleware('*', (req, res) => {
instance.addMiddleware('*', async (req, res) => {
if (req.url.toLowerCase().endsWith('.svg')) {
// Make sure SVGs error out in dev instead of serve the 404 page
res.writeHead(404);
} else {
res.writeHead(302, { location: '/404.html' });
try {
const notFoundTemplate = await readFile(join(siteDir, '404.html'), 'utf-8');
res.writeHead(404);
res.write(notFoundTemplate || 'Page Not Found');
} catch {
// We're probably disconnected for some reason, so fail gracefully
}
}
res.end();