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

Support useEvent (async context) in cloudflare workers #1943

Open
ManasMadrecha opened this issue Nov 22, 2023 · 1 comment
Open

Support useEvent (async context) in cloudflare workers #1943

ManasMadrecha opened this issue Nov 22, 2023 · 1 comment

Comments

@ManasMadrecha
Copy link

ManasMadrecha commented Nov 22, 2023

Environment

Nitro 2.8.0
Nodejs: 20 (on my windows 11), but, in production, using Cloudflare pages preset while building my app.

Reproduction

Using useEvent() directly instead of explicitly passing in event gives this error: 500 Nitro request context is not available. Note: This is an experimental feature and might be broken on non-Node.js environments.

Describe the bug

Of course, Cloudflare is not node environment, so the error is logical and clearly states this. But, is there any way can we have this feature in non-node environment? I mean is it actually possible? Else I will simply have to keep passing event in each function in the utils folder. Thanks.

Additional context

Currently, the Nitro docs say:

This feature is currently supported for Node.js and Bun runtimes and also coming soon to other presets that support AsyncLocalStorage interface.

Also, these are the docs for Async Local Storage option in Cloudflare. https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/#caveats. Do these caveats prevent Nitro from adding this feature in Cloudflare Pages preset?

Logs

No response

@pi0 pi0 changed the title Error 500 Nitro request context is not available. Note: This is an experimental feature and might be broken on non-Node.js environments. Support useEvent (async context) in cloudflare workers Dec 21, 2023
@pi0
Copy link
Member

pi0 commented Dec 21, 2023

Hi. Support is on the way! (https://github.com/unjs/unenv?tab=readme-ov-file#cloudflare - to be integrated soon with Nitro!)

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