avnav
avnav
CDCloudflare Developers
Created by avnav on 12/28/2023 in #pages-help
pages environment vars
hey guys i posted a question on reddit before remembering discord, maybe you can help out. https://www.reddit.com/r/CloudFlare/comments/18shs8h/how_to_work_with_environment_variables_in_pages/ hey everyone, i made my first site, and i'm hoping to make the code public on my github repo. the site is hosted with cloudflare pages and workers. the workers part is easy: i just have a wrangler.toml file that holds a bunch of variables and i pass them through the context in the workers. but for example, i'm also using the clouflare turnstile - and it requires a site key to be run from the client side. right now, i have it literally sitting in a .ts file. when i go to Workers & Pages for the static webapp, there is a section for Environment variables... but how do i extract those into the actual code. let's say i have: async function renderTurnstile(){ let turnstileToken; const renderParams = { sitekey: CLDFLR_SITEKEY_TO_USE, callback: async function(token: any) { turnstileToken = token; turnstileTokenStore.set(token); await tick(); console.log(Challenge Success ${token}); }, theme: 'dark', appearance: 'interaction-only' }; right now im using: import { CLDFLR_SITEKEY_TO_USE } from '../routes/DevOrProd.ts' which is definitely not recommended. can anyone share how i would load the environment variables i save on the cloudflare website. (also would be great if it were possible to have something similar to a wrangler.toml for the static app to hold the vars)
1 replies
CDCloudflare Developers
Created by avnav on 9/9/2023 in #workers-help
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
4 replies