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

Cloudflare runtime context not available in middleware on 404 page #492

Open
1 task
TorbjornHoltmon opened this issue Dec 22, 2024 · 1 comment
Open
1 task

Comments

@TorbjornHoltmon
Copy link
Contributor

TorbjornHoltmon commented Dec 22, 2024

Astro Info

Astro                    v5.1.1
Node                     v22.3.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             none

Describe the Bug

EDIT

Buffering the body had nothing to do with the issue, I don't know why I got stuck in that thought.

The issue is simply Cloudflare context is not available in middleware on 404 pages in dev.

It works fine when deployed to cloudflare.


When buffering the body in Astro middleware, the Cloudflare context is unavailable in development.

Example of buffering body in middleware:

// Irrelevant
// const res = await next();

// const body = await res.arrayBuffer();

// return new Response(body, res);

The full example can be found in repro, running the repro in dev and going to any two-segment route (/123/456) will trigger the error.

I am not sure if this is an adapter issue or a astro main repo issue.
I am starting here, since it is the Cloudflare context that is unavailable.

What's the expected result?

The Cloudflare context should always be available in middleware

Link to Minimal Reproducible Example

https://github.com/TorbjornHoltmon/missing-cloudflare-context-repro

Participation

  • I am willing to submit a pull request for this issue.
@TorbjornHoltmon TorbjornHoltmon changed the title Cloudflare runtime context not available on 404 pages when buffering response body in middleware Cloudflare runtime context not available on 404 pages in middleware Dec 23, 2024
@TorbjornHoltmon
Copy link
Contributor Author

TorbjornHoltmon commented Dec 23, 2024

I was wrong about the body buffering, it had nothing to do with the issue.

The context is just not available in middleware on 404 pages (404 rewrites?).

@TorbjornHoltmon TorbjornHoltmon changed the title Cloudflare runtime context not available on 404 pages in middleware Cloudflare runtime context not available in middleware on 404 page Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants