this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: require Turso config in hosted deployments

Made-with: Cursor

+23 -1
+23 -1
lib/db.ts
··· 31 31 } 32 32 } 33 33 34 + /** Hosted runtimes must have an explicit Turso URL. Falling back to a 35 + * local file database is useful for `deno task dev`, but on Deno Deploy 36 + * it masks configuration mistakes as an empty registry and broken OAuth 37 + * because the web libSQL client can't actually open `file:./local.db`. */ 38 + function isHostedRuntime(): boolean { 39 + return !!(getEnv("DENO_DEPLOYMENT_ID") ?? 40 + getEnv("DENO_REGION") ?? 41 + getEnv("VERCEL")); 42 + } 43 + 34 44 function resolveDbUrl(): string { 35 - return getEnv("TURSO_DATABASE_URL") ?? "file:./local.db"; 45 + const url = getEnv("TURSO_DATABASE_URL"); 46 + if (url) return url; 47 + if (isHostedRuntime()) { 48 + throw new Error( 49 + "TURSO_DATABASE_URL is required in hosted deployments. Set TURSO_DATABASE_URL and TURSO_AUTH_TOKEN to the registry database credentials.", 50 + ); 51 + } 52 + return "file:./local.db"; 36 53 } 37 54 38 55 /** ··· 51 68 _clientPromise = (async () => { 52 69 const url = resolveDbUrl(); 53 70 const authToken = getEnv("TURSO_AUTH_TOKEN"); 71 + if (/^(libsql|https?):\/\//.test(url) && !authToken) { 72 + throw new Error( 73 + "TURSO_AUTH_TOKEN is required when TURSO_DATABASE_URL points at a remote Turso database.", 74 + ); 75 + } 54 76 if (shouldLoadNativeFileClient(url)) { 55 77 const { createClient } = await import("@libsql/client"); 56 78 _client = createClient({ url, authToken }) as unknown as Client;