How do we access production env vars and secrets with the vite-plugin?
I'm unable to read any env and the vite-plugin sidesteps writing the fetch where we can access. The docs are pretty minimal and never shows any example of consuming the env vars and secrets...
https://developers.cloudflare.com/workers/vite-plugin/reference/secrets/
3 Replies
Did you check the
env object (second parameter in your fetch() callback in your worker)?
At least when building a regular worker env vars and secrets are in there.
Information on how to add a worker script in case you don't have one -> https://developers.cloudflare.com/workers/vite-plugin/tutorial/#add-your-api-worker
Cloudflare Docs
Tutorial - React SPA with an API
Create a React SPA with an API Worker using the Vite plugin
I just removed the vite-plugin and things work as expected / documented