-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
enable access to cloudflare runtime #5103
Conversation
🦋 Changeset detectedLatest commit: a134e6e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This is a draft, because i would like some feedback, if there is a wish to integrate the option to |
Hey @AirBorne04, I think that this feature makes sense staying in the cloudflare adapter for now. I'm not sure how generic of a need there really is for this. Outside of cloudflare env is just the environment variables as far as I'm aware. From an implementation perspective this is probably a great solution. From an API perspective it might be a bit low-level for a lot of users who are unfamiliar with symbols. Think we could hide that implementation detail behind a function? Something like: ---
import getRuntime from '@astrojs/cloudflare/runtime';
const runtime = getRuntime(Astro.request);
--- which would just grab it from the symbol. In the future if we ever have some sort of "context" idea like in this RFC: withastro/roadmap#230 then that might be a better place to put it. But I think that idea needs to bake for a while longer. |
Yes I will add the ˋgetRuntimeˋ as an API. For the different runtimes it is not only env variables (But probably the first to spot). In cloudflare it is Platform Features, in netlify it is (data through context and also runtime features through Deno)[https://docs.netlify.com/edge-functions/api/], I think it makes sense to define a general way how to get access to these runtimes / context. Gonna check out the rfc for context. |
d0ad202
to
b9cb9f3
Compare
cb95e83
to
6b39c93
Compare
I am very excited for this PR. Was just running into an issue binding the Cloudflare environment variables but being able to access them directly from the |
ea34637
to
0298664
Compare
@matthewp from my point of view it is ready to go. 👍 |
added context to the runtime in "advanced" mode
0298664
to
d82ab96
Compare
Thanks so much for this! |
How can I access this in dev/HMR mode? Currently I have to manually run |
My current process is I run astro build && fswatch src | (while read; do npx astro build; done) |
Kinda slow but seems like the best solution for now. Thanks |
@AirBorne04 Thank you! This really opens up a lot of use cases for Astro on Cloudflare! |
thank you! @jimjimovich |
Changes
cloudflare
runtime, therefore enables toKV
,Durable Objects
,R2
servicesTesting
Take any example from the repo and add
cloudflare
to astro. Add the following lines into the index:Docs
This would add a piece of documentation to the
cloudflare
worker how it is possible to access services likeKV
,R2
andDurable Objects
./cc @withastro/maintainers-docs for feedback!