Open History to see the last commit
1import { loadEnvFile } from "node:process"
2import { fileURLToPath } from "node:url"
3
4export function runtimeConfig() {
5 // Node's env loader preserves values already supplied by the host/launcher.
6 // Keep credentials in the environment; never expose them through Vite.
7 for (const name of [".env.local", ".env"]) {
8 try {
9 loadEnvFile(fileURLToPath(new URL(`../${name}`, import.meta.url)))
10 } catch (error) {
11 if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error
12 }
13 }
14 const required = (name: string, legacyName?: string) => {
15 const value = process.env[name] ?? (legacyName ? process.env[legacyName] : undefined)
16 if (!value)
17 throw new Error(`Missing ${name}. Copy .env.example to .env and configure your Neon project.`)
18 return value
19 }
20 const databaseUrl = required("DATABASE_URL")
21 // Capabilities must address the same database as the writer (usually neondb
22 // on Neon); a fixed "postgres" name would seal the wrong query scope.
23 const databaseName = decodeURIComponent(new URL(databaseUrl).pathname.slice(1)) || "postgres"
24 return {
25 databaseUrl,
26 databaseName,
27 // Prefer the names emitted by neon env pull. Keep previous deployment
28 // variables working while hosts migrate their environment configuration.
29 realtimeUrl: required("NEON_REALTIME_URL", "REALTIME_PUBLIC_URL"),
30 secret: required("NEON_REALTIME_SECRET", "REALTIME_SECRET"),
31 identitySecret: required("TEAM_COOKIE_SECRET"),
32 port: Number(process.env.API_PORT ?? "3001"),
33 }
34}