Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware not called for non-custom 404 page #7881

Closed
1 task
xriter opened this issue Jul 31, 2023 · 4 comments
Closed
1 task

Middleware not called for non-custom 404 page #7881

xriter opened this issue Jul 31, 2023 · 4 comments
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: error pages Related to 404 and 500 handling (scope) feat: middleware Related to middleware (scope)

Comments

@xriter
Copy link

xriter commented Jul 31, 2023

What version of astro are you using?

2.9.6

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Safari

Describe the Bug

When you have middleware.ts setup, and a custom 404 page, the middleware will get called when you hit a 404 page. However, if you don't have a custom 404 page but rely on the default, the middleware won't get called.

Wondering if this is a deliberate decision?

What's the expected result?

Consistency between the custom and non-custom 404 page. Both should call the middleware.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pt4enm?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 31, 2023
@ematipico
Copy link
Member

@xriter do you have this issue in development AND production?

@ematipico ematipico added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Jul 31, 2023
@xriter
Copy link
Author

xriter commented Jul 31, 2023

@ematipico Yes, in both modes.

@natemoo-re natemoo-re added feat: middleware Related to middleware (scope) - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs response Issue needs response from OP labels Aug 1, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Aug 3, 2023

Even when 404.astro is added, middleware only runs in dev mode.

Repro: https://stackblitz.com/edit/github-pt4enm-xnujgy (added 404.astro and node adapter to the above repro)

Workaround: create a slug route and set Astro.response.status to 404.

Edit: this is a separate issue being tracked in #8154.

@ematipico
Copy link
Member

I am going to close this issue as not planned.

This is the expected behaviour because we can't control default 404 pages, especially in adapters like Vercel, Netlify, etc.

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: error pages Related to 404 and 500 handling (scope) feat: middleware Related to middleware (scope)
Projects
None yet
Development

No branches or pull requests

4 participants