How do I read environment variables from a SvelteKit website?

Hiya, I can't find any resources on how to set up SvelteKit to read environment variables from cloudflare pages environment variables set in the cloudflare dashboard. If anyone knows how to do this, it would be greatly appreciated :-)
4 Replies
kooliebwoykg
kooliebwoykg•2mo ago
Sounds like you've already done half of the work. Once it's defined in the dashboard then use dynamic private for runtime. That's all there is to it. https://svelte.dev/docs/kit/$env-dynamic-private
$env/dynamic/private • Docs • Svelte
$env/dynamic/private • Svelte documentation
Soly
SolyOP•2mo ago
heya, thanks for the help! it now builds successfully, but I don't believe my app can access my api key as the page relying on it won't work. everything works fine in a local server. is there something specific I need to do with cloudflare secrets? reading the value of WorkersAPIKey at runtime with a console.log spits out null nvm, tried switching the secret to a plaintext env variable just to test, and still nothing :( oh my god environment variables only apply to prod😭 I was testing on a preview branch
kooliebwoykg
kooliebwoykg•2mo ago
Lol. Sounds about right. Just gotta add the variables to the preview env. So any updates to variables should be done both on preview and prod.
Mr.Traveller
Mr.Traveller•2mo ago
Hello, @Soly I think you are developing sveltekit project I am a full stack sveltekit developer. May I DM to you?
Want results from more Discord servers?
Add your server