unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.81k stars 489 forks source link

Cloudflare worker adaptor doesn't surface context whilst the pages adaptor does #1054

Open dario-piotrowicz opened 1 year ago

dario-piotrowicz commented 1 year ago

The Cloudflare pages adaptor has been lately improved (https://github.com/unjs/nitro/pull/1004) to surface the env, context and cf object: https://github.com/unjs/nitro/blob/1dcf5c463ffca8776e6c2dc796f16844ff2fcc8f/src/runtime/entries/cloudflare-pages.ts#L40-L47

The same hasn't been applied to the worker adator: https://github.com/unjs/nitro/blob/1dcf5c463ffca8776e6c2dc796f16844ff2fcc8f/src/runtime/entries/cloudflare.ts#L34-L37

So if a user decides to use the worker adaptor they will not have access to the same information as the pages one. (as you can see only the cf object is passed along)

So the same sort of information should be surfaced in the worker adaptor as well.

PS: to correctly pass the environment the adaptor should switch from the service worker syntax to the module one.

Hebilicious commented 1 year ago

@pi0 Should we work towards deprecating the service worker syntax? The only issue that I can think of would be that people using environments variables from global would need to switch to useRuntimeConfig once https://github.com/unjs/nitro/pull/1318 is merged.