import { existsSync } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; /** * Load the repository `.env` (two levels above apps/api) when present, then the cwd `.env`. * Values already set in the environment win (process.loadEnvFile never overrides). */ export function loadEnv(): void { const here = path.dirname(fileURLToPath(import.meta.url)); const candidates = [path.resolve(here, '../../../../.env'), path.resolve(process.cwd(), '.env')]; for (const candidate of candidates) { if (!existsSync(candidate)) continue; try { process.loadEnvFile(candidate); } catch { /* ignore malformed files */ } } process.env.CI_SERVICE ??= 'api'; } export const API_HOST = () => process.env.API_HOST ?? '127.0.0.1'; export const API_PORT = () => Number(process.env.API_PORT ?? 8251);