export interface Config { databaseUrl: string port: number /** Public URL users open in their browser; HTTPS here turns on secure cookies. */ publicUrl: string secureCookies: boolean production: boolean /** Built web app to serve, if present. */ staticDir: string /** e.g. `smtps://user:pass@smtp.example.com:465`. Without it, emails are printed to the log (development only). */ smtpUrl: string | undefined mailFrom: string uploadDir: string maxUploadBytes: number } export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config { const publicUrl = env.PUBLIC_URL ?? `http://localhost:${env.PORT ?? 3000}` return { databaseUrl: env.DATABASE_URL ?? 'pglite://./data/pglite', port: Number(env.PORT ?? 3000), publicUrl, secureCookies: publicUrl.startsWith('https://'), production: env.NODE_ENV === 'production', staticDir: env.STATIC_DIR ?? 'dist', smtpUrl: env.SMTP_URL || undefined, mailFrom: env.MAIL_FROM ?? 'Open SafetyLog EHS ', uploadDir: env.UPLOAD_DIR ?? './data/uploads', maxUploadBytes: Number(env.MAX_UPLOAD_MB ?? 10) * 1024 * 1024, } }