Do I need to store my environment variables in wrangler.toml?
Do env vars need to be defined in the
wrangle.toml
? I initially have the env var in .dev.vars
, and manually added the value for the env var in the Cloudflare, however, whenever I deploy the worker, it overrides the env var I manually configured. The worker is a public github, and I would rather not have the env var exposed. I know I could just use a secret, I would rather have env vars seperate from the code.8 Replies
Environment Variables defined within
wrangler.toml
overwrite anything defined on the Dashboard. The only thing that isn't overwritten are secrets, as they have to be pushed manuallyInitially, I did not have any env vars defined, but when I deployed, it cleared out the one I defined manually in the dashboard. It that expected?
Yes. When using a
wrangler.toml
, it is the single source of truth for how your Worker is configuredOK, so after every deploy, i would need to go an set the env var in the dashboard again?
I’m not entirely sure why a Secret wouldn’t work here?
it definitely can. I am just trying to understand how env vars work. It feels odd to me to have the env set in the code. I might as well just hardcode the value since I do not have multiple envs
Those variables are for things you don’t mind being public, for example an API URL. The token for said API might be a secret
Two separate usecases, even though the end product is sort of similar
Thank you