CONVEX_SITE_URL undefined in functions?
Seems
process.env.CONVEX_SITE_URL
inside queries is undefined? But the docs say that this system env var is always available inside convex functions?4 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
It should definitely be defined in queries. Do you have some example function where it doesn't work?
@Nicolas figured out that
env.CONVEX_SITE_URL
becomes undefined when using ctx.runQuery(api.getUrl)
. However, using useQuery(api.getUrl)
- i.e. using the function directly via the client it is defined as it should be. Using a function via another function it seems to become undefined.
Repro:
This logs and returns correctly when doing either on frontend:
OR
However doing this in convex backend:
Logs and returns undefined - so assuming some issue with propagation of env variables with ctx transfer between functions?Yeah this is because ctx.runQuery is designed to be used with components (convex.dev/components), which do not have access to CONVEX_SITE_URL (because they don't know where their http actions will be exposed).
We recommend you call a helper function instead of doing ctx.runQuery https://docs.convex.dev/understanding/best-practices#use-helper-functions-to-write-shared-code
Best Practices | Convex Developer Hub
This is a list of best practices and common anti-patterns around using Convex.