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
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.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.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 enoughThis is supported, just not obvious: once you switch the CONVEX_DEPLOYMENT and use
npx convex dev --prod
you can develop live against prodah 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 itIf 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
I get the error when using prod env vars, but without passing
--prod
to the CLI:
It still worked, just printed the error.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.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:
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"
ah, yes I did include convex.cloud
the generated CONVEX_DEPLOYMENT for dev includes it, is that dev specific
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)
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:
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
@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.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
I'll check again to make sure
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.
@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):
- 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 dbWhen 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?
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?
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.
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
totally, yeah when building an application without authentication or sessions or a secret it's important to think about these being public
now if convex would just write this pesky code for me
okay cool, thanks for talking this through! makes sense