SPB Git

spb/cancerindex

Public
854 B · 25 lines typescript
1import { existsSync } from 'node:fs';2import path from 'node:path';3import { fileURLToPath } from 'node:url';45/**6 * Load the repository `.env` (two levels above apps/api) when present, then the cwd `.env`.7 * Values already set in the environment win (process.loadEnvFile never overrides).8 */9export function loadEnv(): void {10  const here = path.dirname(fileURLToPath(import.meta.url));11  const candidates = [path.resolve(here, '../../../../.env'), path.resolve(process.cwd(), '.env')];12  for (const candidate of candidates) {13    if (!existsSync(candidate)) continue;14    try {15      process.loadEnvFile(candidate);16    } catch {17      /* ignore malformed files */18    }19  }20  process.env.CI_SERVICE ??= 'api';21}2223export const API_HOST = () => process.env.API_HOST ?? '127.0.0.1';24export const API_PORT = () => Number(process.env.API_PORT ?? 8251);25
Files · 91a859e8843131acb6ef1dc81672354ca6e56ee3
Menu

Theme