DEV vs PROD envs

hey guys i have a question about managing DEV and PROD envs... im using cloudflare pages and workers right now, i have a wrangler.toml file for the workers and it has something like [env.luciaprod.vars] a then i run wrangler dev --env luciaprod and it spits out all the vars, which is awesome. one of those vars is DEV_OR_PROD="DEV" which i use as a toggle for the backend. but id also like to use it as a toggle for the frontend! in fact, i'm a noob, so i have a DevOrProd.ts where i have all the conditionals. and i'm trying to use that for frontend and back, but not really working out for me... any advice? it seems like i cant pull from the .env when using wrangler so thats my trouble. using sveltekit btw for framework
2 Replies
Phisn
Phisn16mo ago
What you could do is use different scripts for different environments. One npm dev and npm dev:prod. They both would no run different scripts in your packages. Specifically in your worker you would start it with something like wrangler ... --vars=DEV_OR_PROD:PROD or :DEV. For deployment you would just use your wrangler.toml vars.
Tin Cap
Tin Cap16mo ago
I build my React front-end separately per environment because I need to compile different variables in per environment. For smaller projects, I'll just check the domain. Something along the lines of const isProd = window.location.hostname === "mydomain.com" (this may not be valid code, but you get the idea)
Want results from more Discord servers?
Add your server