chore: load convex env from .env.local and support CONVEX_URL fallback

This commit is contained in:
Codex
2026-02-18 14:36:32 +00:00
parent 77f7f10921
commit 0ed3d2b4fe
4 changed files with 21 additions and 3 deletions

3
.gitignore vendored
View File

@@ -3,3 +3,6 @@ node_modules/
.DS_Store
coverage/
src/public/styles.css
.env.local
convex/_generated/

View File

@@ -9,7 +9,9 @@
"dev": "bun run build:css && bun --watch src/server.js",
"start": "bun run build:css && bun src/server.js",
"test": "bun run build:css && bun test",
"lint": "bunx eslint src test"
"lint": "bunx eslint src test",
"convex:dev": "bunx convex dev",
"convex:deploy": "bunx convex deploy"
},
"keywords": [],
"author": "",

View File

@@ -1,6 +1,7 @@
"use strict";
require("dotenv").config({ quiet: true });
require("dotenv").config({ path: ".env.local", quiet: true });
require("dotenv").config({ path: ".env", quiet: true });
const { z } = require("zod");
@@ -55,7 +56,7 @@ const parsed = {
betterAuthBasePath: strFromEnv("BETTER_AUTH_BASE_PATH", "/api/auth"),
betterAuthDevPassword: strFromEnv("BETTER_AUTH_DEV_PASSWORD", "xartaudio-dev-password"),
internalApiToken: strFromEnv("INTERNAL_API_TOKEN", ""),
convexDeploymentUrl: strFromEnv("CONVEX_DEPLOYMENT_URL", ""),
convexDeploymentUrl: strFromEnv("CONVEX_DEPLOYMENT_URL", strFromEnv("CONVEX_URL", "")),
convexAuthToken: strFromEnv("CONVEX_AUTH_TOKEN", ""),
convexStateQuery: strFromEnv("CONVEX_STATE_QUERY", "state:getLatestSnapshot"),
convexStateMutation: strFromEnv("CONVEX_STATE_MUTATION", "state:saveSnapshot"),

View File

@@ -37,6 +37,7 @@ test("config uses defaults when env is missing", () => {
BETTER_AUTH_SECRET: "",
BETTER_AUTH_BASE_PATH: "",
INTERNAL_API_TOKEN: "",
CONVEX_URL: "",
QWEN_TTS_MODEL: "",
MINIO_SIGNED_URL_TTL_SEC: "",
MINIO_USE_SSL: "",
@@ -68,6 +69,7 @@ test("config reads convex/qwen/minio overrides", () => {
BETTER_AUTH_DEV_PASSWORD: "xartaudio-dev-password",
INTERNAL_API_TOKEN: "internal-token",
CONVEX_DEPLOYMENT_URL: "https://example.convex.cloud",
CONVEX_URL: "https://should-not-win.convex.cloud",
CONVEX_AUTH_TOKEN: "convex-token",
CONVEX_STATE_QUERY: "state:get",
CONVEX_STATE_MUTATION: "state:put",
@@ -104,3 +106,13 @@ test("config reads convex/qwen/minio overrides", () => {
assert.deepEqual(config.abuse.denyUserIds, ["u1", "u2"]);
});
});
test("config falls back to CONVEX_URL when deployment url variable is absent", () => {
withTempEnv({
CONVEX_DEPLOYMENT_URL: "",
CONVEX_URL: "https://from-convex-url.convex.cloud",
}, () => {
const { config } = require("../src/config");
assert.equal(config.convexDeploymentUrl, "https://from-convex-url.convex.cloud");
});
});