Hi all,
I’m considering moving from Heroku to Netlify for my NextJS 12 app. I have a few NextJS API routes in my app, one of which depends on an API key/secret that I store as an environment variable (ESV_API_KEY).
App URL: https://staging.faithdashboard.com/
API Route (that should work): https://staging.faithdashboard.com/api/widgets/bible-verse?q=ps23.1
Relevant Code: faith-dashboard/bible-verse.ts at main · caleb531/faith-dashboard · GitHub
Now here’s the problem:
- Locally, my environment variable is stored in a gitignore’d
.env.local
file so it’s not committed publicly. - On Heroku, I can set this environment variable in the dyno settings, and it gets passed through to my API route without any additional configuration.
- But on Netlify, my API route is showing the environment variable (ESV_API_KEY) as undefined, even though I’ve defined it in the Netlify Deploy Settings (screenshot below). And I have made sure to redeploy after setting the env variable, but still no luck. You can see the behavior if you visit the API route URL above
Now, I have read [Support Guide] Using environment variables on Netlify correctly, but it’s very framework-agnostic, and I’m not sure what the minimal steps are I need to take for my NextJS app specifically.
Thanks in advance,
Caleb