stibbs
stibbs
CDCloudflare Developers
Created by stibbs on 5/1/2024 in #pages-help
How do I work with local D1 in a SvelteKit project?
I don’t know how to mark as solved (on my phone currently and can’t see an option?)
8 replies
CDCloudflare Developers
Created by stibbs on 5/1/2024 in #pages-help
How do I work with local D1 in a SvelteKit project?
Yes, following those two guides did the trick
8 replies
CDCloudflare Developers
Created by stibbs on 5/10/2024 in #workers-help
How to rapidly validate if a JS package will work on Workers runtime?
Do most (complying) packages mention that? https://github.com/stripe/stripe-node (this is what pnpm add stripe installs) doesn’t seem to mention it but does work? Maybe I’m looking in the wrong place
5 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
But the other way could also work
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
Ah right. I was thinking it was a wrangler bug and they could make them accessible as env vars instead of bindings
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
...do you know where I would do that?
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
But you are right I'll submit a bug 🙂
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
It does work when deployed, it's the local dev experience that requires the workaround
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
The lesser evil is probably just keeping your local dev .env aligned to your wrangler.toml
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
Yes for secrets it would be equivalent. But then you need a workaround for non-secret environment variables as we discussed. Neither approach is "great"
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
https://developers.cloudflare.com/workers/configuration/environment-variables/ is clear that wrangler environment variables are bindings, not environment variables. Environment variables are a type of binding that allow you to attach text strings or JSON values to your Worker.
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
Using the platform.env. approach makes me fear for my future self when I've forgotten what I've done and something goes wrong 😅
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
Via a load?
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
That's a good point, how do you access the platform vars in client code..?
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
I like the safety the SvelteKit approach provides. There is no way to accidentally leak secrets into the client using their import methods
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
I just did a little console.log experiment to validate that
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
It does read wrangler.toml but it does not appear to map items listed under [vars] to be environment variables. They are accessible via platform.env.KEY but not the SvelteKit methods
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
It is worth noting that you cannot import PUBLIC_ keys using either /private variant, despite this seemingly posing no risk. Those variants exist to ensure you don't accidentally leak secrets into the client, but the opposite risk isn't real (leaking public keys into your server?) Slightly weird but it is clear I suppose 😅
52 replies
CDCloudflare Developers
Created by stibbs on 5/6/2024 in #pages-help
Are environment variables available at build or only runtime?
That was the trick: creating environment variables in wrangler.toml (and encrypted secrets via dashboard) makes them accessible via the SvelteKit methods in deployed code: - import { env } from '$env/dynamic/private'; for runtime secrets - import { env } from '$env/dynamic/public'; for PUBLIC_ runtime vars - import { SECRET } from '$env/static/private'; for static secrets - import { PUBLIC_KEY } from '$env/static/public'; for PUBLIC_ static vars Locally you will need to maintain parity between .env (to make pnpm run dev work) and wrangler.toml for your deployments to succeed. You can also access them via platform.env.PUBLIC_KEY but I prefer to use the SK way.
52 replies