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

[Workers] Callout AsyncLocalStorage as a Workers alternative for getPlatformProxy #13146

Closed
KianNH opened this issue Feb 26, 2024 · 1 comment
Assignees
Labels
content:new Request for new/missing content documentation Documentation edits product:workers Related to Workers product

Comments

@KianNH
Copy link
Contributor

KianNH commented Feb 26, 2024

Which Cloudflare product(s) does this pertain to?

Workers

Subject Matter

ALS as a way to get req/env/ctx anywhere in Workers

Content Location

getPlatformProxy allows users to access their Workers bindings and mock information like req.cf and ctx.waitUntil(), allowing them to write code for Workers without using Wrangler's development emulation (i.e next dev when using next-on-pages)

The availability of these variables, without having to pipe them from a handler, is a common request on Workers and can be done with AsyncLocalStorage.

The current documentation for getPlatformProxy states...

getPlatformProxy cannot be run inside the Workers runtime.

It would be helpful if there was a guide on using AsyncLocalStorage to do the same, and link out to it - I suspect people will come across this page when trying to figure out if that use-case is possible.

The top 5 results for a Google search of "cloudflare workers asynclocalstorage for env" are:

  1. process.env docs (doesn't work for bindings)
  2. a community post (talks about using AsyncLocalStorage to implement this)
  3. environment variables docs (no mention of AsyncLocalStorage)
  4. AsyncLocalStorage docs (no mention of using it within imports, libraries or using it to store per-request state)
  5. a next-on-pages issue (talks about using AsyncLocalStorage to implement this).

Additional information

No response

@KianNH KianNH added content:new Request for new/missing content documentation Documentation edits labels Feb 26, 2024
@kodster28 kodster28 added the product:workers Related to Workers product label Apr 23, 2024
@KimJ15 KimJ15 assigned KianNH and unassigned deadlypants1973 Sep 27, 2024
@KimJ15
Copy link
Collaborator

KimJ15 commented Oct 1, 2024

This issue is pretty stale. Closing as won't do for now.

@KimJ15 KimJ15 closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content:new Request for new/missing content documentation Documentation edits product:workers Related to Workers product
Projects
None yet
Development

No branches or pull requests

4 participants