Astro info
Astro version v2.10.14
Package manager npm
Platform darwin
Architecture arm64
Adapter Couldn't determine.
Integrations None or couldn't determine.
What browser are you using?
Chrome
Describe the Bug
Middleware isn't invoked before rendering the default 404 page.
NB: I'm uncertain if this is a bug or the intended behaviour
- Consider the basic middleware below:
import { defineMiddleware } from "astro/middleware";
export const onRequest = defineMiddleware((context, next) => {
console.log("in middleware");
return next();
});
- Visit a random page route: e.g.,
/uhoihoijoijoijoijoi
Result: The middleware is never invoked. No logs.
- Add a custom 404.astro page
// src/pages/404.astro
---
console.log("404 page");
---
Now, the middleware will be invoked before rendering the custom 404.astro page.
#logs
in middleware
404 page
What's the expected result?
Consistently invoke the middleware for both custom and default 404 pages.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-i9px2m?file=src%2Fmiddleware%2Findex.ts
Participation
Astro info
What browser are you using?
Chrome
Describe the Bug
Middleware isn't invoked before rendering the default
404page.NB: I'm uncertain if this is a bug or the intended behaviour
/uhoihoijoijoijoijoiResult: The middleware is never invoked. No logs.
Now, the middleware will be invoked before rendering the custom
404.astropage.What's the expected result?
Consistently invoke the middleware for both custom and default 404 pages.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-i9px2m?file=src%2Fmiddleware%2Findex.ts
Participation