-
-
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
Creating a new Response with a Status Code of 404 leads to an infinite loop when the /404.astro page is absent. #8100
Comments
@gitcaduff Could not reproduce the issue. The custom 404 response gets served. Could you check? |
Hi @lilnasy, thanks for your ultrafast reply! |
@lilnasy it seems that the problem got back with Astro 4.5.x |
Could you open a new issue with a small reproduction project that runs into the loop? |
Done: #10581 |
This almost killed my whole Firebase budget, as a export const onRequest: MiddlewareHandler = async (
{ request },
next,
): Promise<Response> => {
// pre-flight request
if (request.method === "OPTIONS") {
console.log("Middleware allowed pre-flight request, 200 OK");
return new Response(null, { status: 200 });
}
try {
console.log("Middleware blocked request with no valid auth");
return new Response("Not found", { status: 404 });
} catch (error) {
console.log("Middleware error", error.message, error.stack);
logException(error);
return new Response("Internal Server Error", { status: 500 });
}
}; Once I access http://localhost:4321/, it's over:
|
Btw there is no way now to return any |
@kyr0 The issue is a systematic one, explained in-depth here: withastro/roadmap#681. There are likely multiple manifestations of it still in the codebase. It seems like middleware returning 404 responses is still problematic.
|
What version of
astro
are you using?2.10.9
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?
Chrome
Describe the Bug
In the past, with an older version of Astro (until 2.8.4), it was feasible to generate Responses bearing the 404 status code. However, in the current setup (version 2.9.0 and above), this process triggers an infinite loop due to Astro's subsequent search for the missing /404.astro page. To circumvent this loop, I opt not to furnish a /404.astro page. This choice stems from my desire to refrain from redirecting users to a dedicated 404 page. Instead, I intend to furnish a 404 Code directly while retaining the requested URL's context.
What's the expected result?
I would expect to be able to return any page with a 404 code.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/stackblitz-starters-6pmtt6?file=response-with-404-code%2Fsrc%2Fpages%2F[...path].astro
Participation
The text was updated successfully, but these errors were encountered: