erquhart
erquhart16mo ago

Possible to hit production from my local machine?

Is there a way to do this for debugging purposes? Hitting some issues due to data that's in prod but not dev, and I'm not sure which data is responsible.
25 Replies
erquhart
erquhartOP16mo ago
Hmm I switched CONVEX_DEPLOYMENT to prod:<deployment>, and the CLI warns that I don't have access, but it is indeed working. Which, I don't know whether to be concerned or not lol. It's obviously using my authentication so it's fair to say access should work.
Michal Srb
Michal Srb16mo ago
Yes, the CLI should work although we recommend carefully and manually using npx convex deploy instead of npx convex dev against a production deployment (via setting CONVEX_DEPLOYMENT as you figured out). Less powerful commands like npx convex run and npx convex logs take a --prod flag, so you don't need to change CONVEX_DEPLOYMENT for those either.
erquhart
erquhartOP16mo ago
The case for npx convex dev in this case was getting a dev environment (live reload as I'm troubleshooting, for example) against prod data. This would be a no go once I have other people's data in production, but useful for early iteration. But yeah I guess it's a big enough footgun to not support it, fair enough
ballingt
ballingt16mo ago
This is supported, just not obvious: once you switch the CONVEX_DEPLOYMENT and use npx convex dev --prod you can develop live against prod
erquhart
erquhartOP16mo ago
ah okay, so the access warning can be ignored if I'm doing it on purpose oh I didn't realize --prod worked for the dev command, got it
ballingt
ballingt16mo ago
If you've got that warning handy I'd love to see it, I can only get an error without --prod or it working with --prod (once i've changed the CONVEX_DEPLOYMENT) yeah --prod is required for dev but unlike --prod flags for other commands it's not sufficient, you also have to change CONVEX_DEPLOYMENT
erquhart
erquhartOP16mo ago
I get the error when using prod env vars, but without passing --prod to the CLI:
✖ You don't have access to the project with deployment friendly-kudu-995.convex.cloud, as configured in CONVEX_DEPLOYMENT
? Configure a different project? (Use arrow keys)
✖ You don't have access to the project with deployment friendly-kudu-995.convex.cloud, as configured in CONVEX_DEPLOYMENT
? Configure a different project? (Use arrow keys)
It still worked, just printed the error.
ballingt
ballingt16mo ago
So it says "configure a different project" but doesn't make you choose one? Was this from running npx convex dev directly or from a script? Thanks, this is helpful to see.
erquhart
erquhartOP16mo ago
It gave me the option to create a new project only. Maybe it had inferred that the deployment didn't belong to either of my dev projects? I was running npm start, my scripts:
"start": "npm run dev",
"dev": "concurrently --raw \"npm:dev-frontend\" \"npm:dev-backend\"",
"dev-frontend": "vite --host",
"dev-backend": "npx convex dev --tail-logs",
"start": "npm run dev",
"dev": "concurrently --raw \"npm:dev-frontend\" \"npm:dev-backend\"",
"dev-frontend": "vite --host",
"dev-backend": "npx convex dev --tail-logs",
ballingt
ballingt16mo ago
Ah ok I can repro this, could the issue have been including ".convex.cloud" in the CONVEX_DEPLOYMENT envar? We can improve this error. When I remove the .convex.cloud a get a better error saying "this is a prod environment"
erquhart
erquhartOP16mo ago
ah, yes I did include convex.cloud the generated CONVEX_DEPLOYMENT for dev includes it, is that dev specific
ballingt
ballingt16mo ago
Generated when/where? There's a CONVEX_URL I see that has this, we'll improve the parsing here to make it clear it that CONVEX_DEPLOYMENT shouldn't include it (or just allow it)
erquhart
erquhartOP16mo ago
I used the React quickstart with Vite for a small side project, an .env.local appeared at some point, honestly not sure when as I noticed it much later. That looked like:
# Deployment used by `npx convex dev`
CONVEX_DEPLOYMENT=dev:<project-id> # team: <team>, project <project-name>

VITE_CONVEX_URL="https://<project-id>.convex.cloud"
# Deployment used by `npx convex dev`
CONVEX_DEPLOYMENT=dev:<project-id> # team: <team>, project <project-name>

VITE_CONVEX_URL="https://<project-id>.convex.cloud"
ballingt
ballingt16mo ago
Cool, that makes sense. We'll improve the parsing so it's clear what's wrong if .convex.cloud is included in CONVEX_DEPLOYMENT accidentally or isn't included in CONVEX_URL
erquhart
erquhartOP16mo ago
@ballingt I just had some issues while developing locally and thought oh crap, did I leave this thing set to production?? It wasn't! All good. But that brings to mind something that got buried here - I was able to hit production without passing the --prod flag. I'd feel a lot safer knowing that wouldn't work. There was an error message, but it still worked.
ballingt
ballingt16mo ago
Have you been able to repro that? I haven't been able to — from the above conversation I was wondering if it wasn't actually working, since instead it prompted you to create a new deployment I might have misunderstood this, my impression was that it wasn't syncing and instead made you create a new deployment @erquhart
erquhart
erquhartOP16mo ago
I'll check again to make sure
ballingt
ballingt16mo ago
Thank you, as you point out this is important to fix if it is. I haven't made the error message changes we talked about above yet, when I'm testing those I'll also try.
erquhart
erquhartOP16mo ago
@ballingt confirmed that convex dev is running against production while showing that error message in the console, I was able to mutate production values No --prod flag being used steps to repro: - .env.local (included the vite env var, but that may not be relevant):
CONVEX_DEPLOYMENT=prod:some-prod-project.convex.cloud
VITE_CONVEX_URL="https://some-prod-project.convex.cloud"

CONVEX_DEPLOYMENT=prod:some-prod-project.convex.cloud
VITE_CONVEX_URL="https://some-prod-project.convex.cloud"

- npx convex dev --tail-logs (logs part probably isn't required, but didn't test) - wait for the error prompting for a selection - don't respond to the prompt - make a mutation in the local dev environment - check prod db
ballingt
ballingt16mo ago
When I try this I see my frontend connected to "https://some-prod-project.convex.cloud" (because of the VITE_CONVEX_URL variable, but I can't make changes to the deployment. Am I understanding that right, the issue here is that the frontend is connected to prod?
erquhart
erquhartOP16mo ago
Yeah I'm making the change to the frontend when I'm mutating, that is oh wow, it works even without convex dev running, I see what you mean why would that work?
ballingt
ballingt16mo ago
That makes sense, a Convex client will connect to whatever URL you give it; there's no authentication needed here. I didn't follow what the concern was before, now I get it. Yeah we could try to detect a convex client running in a dev environment (e.g. we could check in the frontend for NODE_ENV being "development") and warn in the console that maybe this is a mistake. But it's somewhat common to run against a production backend when e.g. just editing frontend code or CSS.
erquhart
erquhartOP16mo ago
just hitting me how wide open my production db is 😅 For some reason I thought convex was doing something extra with how I was connecting locally, but I guess it makes sense that those endpoints just need to be authenticated the magic of convex is making me stupid lol great work guys
ballingt
ballingt16mo ago
totally, yeah when building an application without authentication or sessions or a secret it's important to think about these being public
erquhart
erquhartOP16mo ago
now if convex would just write this pesky code for me okay cool, thanks for talking this through! makes sense

Did you find this page helpful?