Next.js Discord

Discord Forum

Edge Function Environment variables.

Answered
Blue swimming crab posted this in #help-forum
Open in Discord
Blue swimming crabOP
I've recently started implementing Neon's serverless driver into some edge routes in my app. I've noticed that edge functions won't ship with environment variables in .env* files unless they're prepended with NEXT_PUBLIC_. (per: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#environment-variables-on-vercel)

We use Neon's branching feature in our preview environments so each preview environment has its own unique DB connection string. Typically we write that new connection string to a .env file in CI, bundle the app and everything works as we'd expect. Now, however, we have edge functions that need that unique DB string and I'm struggling with a reasonable way to include it with the edge functions outside of just prepending the connection string with NEXT_PUBLIC_

Curious if anyone has any ideas here
Answered by Blue swimming crab
Ah, that might do it -- something like vercel env add [name] [environment] [gitbranch]
View full answer

5 Replies

Blue swimming crabOP
Ah, that might do it -- something like vercel env add [name] [environment] [gitbranch]
Answer
Not sure about the CLI side but yeah that probably works too
Blue swimming crabOP
Cool, I think there's still some things for me to figure out -- We don't have github integration hooked up at the moment and are managing deploys ourselves (w/ vercel cli in gh workflows) so we don't end up with a deployment -> git branch link. I'll see if we can re-enable the integration, or if there's another way for us to approximate that same linking behavior without the integration. I'll mark as solved. Thanks
Yeah, good luck. This does sound like an interesting idea that I might need in the future