Prod deploy on Netlify using Dev DB?
Hey, just deployed my first Convex app on Netlify. So easy! Thanks for making it such a smooth experience!
One snag: I'm seeing that my deployed app is hitting my dev db/instance. I've double checked that I used the right deploy key and all, so I'm not sure what to check on next. What could be up? Let me know if any links/screenshots would be helpful!
Thanks!
10 Replies
Hi Jenna! There's an environment variable or hardcoded string separate from the deploy key for which deployment the frontend talks to, might be called CONVEX_URL or NEXT_PUBLIC_CONVEX_URL or VITE_CONVEX_URL etc. https://github.com/get-convex/convex-tutorial/blob/e6d114558b30d2de578c711cd35590d436f05e70/src/main.jsx#L7
GitHub
bernard/.env at convex-trial · jennazee/bernard
Contribute to jennazee/bernard development by creating an account on GitHub.
Yeah, ideally the prod bundle would be using that one and the dev bundle/dev server would be using the .env.local one
Is that something I could have conceivably mixed up myself? 😅
(also hi!)
I mix them up sometimes so yeah maybe? During the project setup process it writes the dev URL to .env.local and the prod URl to .env, so that part is more likely right
from the repo, those files say utmost-beaver should be dev and stoic-salmon should be prod
Yeah. I see the deployed version hitting utmost-beaver in the Network panel https://convex-trial--animated-dodol-09cd7e.netlify.app/
@jenna a colleague just pointed out to me that since this .env.local isn't .gitignored, that file of credentials is probably being preferred in Netlify
we have some changes in the pipeline to examine the .gitignore file and add .env.local to help with this
Ah, there's also this in the Netlify docs (https://docs.netlify.com/configure-builds/environment-variables/). After I imported the .env file it's now pinging stoic-salmon, so yay
Note that when you build on Netlify, the build system doesn’t read .env files. To use variables declared in a .env file, we recommend you import the variables into Netlify before you build. This way the variables in your .env file remain secure and out of your shared repository.
Ah good pointer. Currently the automatic flow is more Vercel-centric, they suggest committing the .env, but we're moving to recommending this Netlify style where these are added manually.
Hm I wonder if Vite still reads these environment variables from .env on Netlify — guessing it was Vite choosing .env.local over .env
Glad things are working, helpful feedback for us to clean this up!
Yeah! Thanks for going on this journey with me, and thanks to your colleague for the nudge that something might have been weird about reading from .env
In the meantime, could be worth adding a line to the Convex with Netlify instructions about importing the other env variables alongside the deploy key since that's unexpected?https://docs.convex.dev/production/hosting/netlify
Using Convex with Netlify | Convex Developer Hub
Host your frontend on Netlify and your backend on Convex.