- Replaced global navbar, now mobile friendly
- Corrected sizing of LyricSearchInputField - Removed sitemap from auto-generated robots.txt
This commit is contained in:
20
src/middleware.js
Normal file
20
src/middleware.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineMiddleware } from 'astro:middleware';
|
||||
|
||||
export const onRequest = defineMiddleware(async (context, next) => {
|
||||
try {
|
||||
// Let Astro handle the request first
|
||||
const response = await next();
|
||||
|
||||
// If it's a 404, redirect to home
|
||||
if (response.status === 404) {
|
||||
console.log(`404 redirect: ${context.url.pathname} -> /`);
|
||||
return context.redirect('/', 302);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
// Handle any middleware errors by redirecting to home
|
||||
console.error('Middleware error:', error);
|
||||
return context.redirect('/', 302);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user