Convex self-hosted
Conventions for Convex projects running on self-hosted backends
Self-hosted Convex env + auth conventions. Applies WHEN a project has **/convex/_generated/ and CONVEX_SELF_HOSTED_URL in any .env.
MUST
- Keep all Convex env vars in
apps/backend/.env(or.env); push via a singlesync.ts(bun run sync). Why:.envis sole source of truth. - Gate dev/prod branches on a custom var (
ALLOW_OVERRIDES) orprocess.env.CONVEX_SELF_HOSTED_URL. Why: self-hosted runtime hardcodesNODE_ENV==='production'on dev AND prod. - WHEN depending on
@convex-dev/auth, defineJWT_PRIVATE_KEY+JWKSin.env; persistsync.tsauto-generated values back to.env. Why: backend + source of truth stay aligned. - Set
SITE_URLfor auth callbacks; multi-origin (prod + localhost + 127.0.0.1) = comma-separated list. Why: callback matchesredirectToagainst the full set.
NEVER
convex env setliteral outside**/sync.ts. Cost: drift;syncsilently overwrites it.- Branch on
process.env.NODE_ENVinside**/convex/**/*.ts. Cost: always'production', branch is dead.