-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Rewrite in middleware incorrectly returns a 404 response #11461
Comments
I provided more details on the other issue here #11306 (comment), but this isn't just an issue with rewrites. A simple middleware that just returns a static 200 response on certain paths will also still return a 404 status despite what the |
Does this issue only affect the dev server, @FugiTech ? |
That's unrelated to rewrites. Your middleware is triggered when rendering a 404. This was changed a few months ago, because users wanted to have their middleware triggered on 404 routes for some cleanup logic. However, I'm not happy with this logic and I think we will change it (not sure how and when) |
@ematipico interesting, so you're saying that the middleware which is allowed to return a |
No, I am saying that if you hit a page that doesn't exist, the |
I'm writing a middleware that effectively adds some more routes to the app, but those routes added by the middleware always respond with |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
experimental: { rewriting: true }
middleware.ts
file that returnsnext(context.url.pathname === '/foo' ? '/' : undefined)
/
: it will return a 200 with the body set to the index html/foo
: it will return a 404 with the body set to the index html/bar
: it will return a 404 with the body set to the default error pageI believe this is because
/foo
does not exist insrc/pages
, so Astro keeps the original 404 status code instead of respecting the status code of the rewrite. I believe it was previously reported as #11306 but the fix did not fully fix the issue.This is especially a problem with Astro's prefetching, as the 404 prevents the prefetch from being used.
What's the expected result?
Visiting
/foo
should return a 200 status codeLink to Minimal Reproducible Example
https://stackblitz.com/edit/github-njawah?file=src%2Fmiddleware.ts
Participation
The text was updated successfully, but these errors were encountered: