oweme/apps/server/src/config.ts
agent 04d952872d Make the deploy panel-friendly: zero-config compose, env vars with defaults
- compose.yaml runs only the app by default; Caddy moved to the
  'standalone' profile (the panel brings its own Caddy and routes).
- No env_file: every setting is ${VAR:-default} in compose.yaml, so it
  can be set from the panel's Environment tab (or .env standalone).
- VAPID keys are generated on first start and kept in the data volume;
  the push subject defaults to https://<site domain>. gen-vapid.ts removed.
- PUSH_DISABLED=1 turns push off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
2026-10-09 22:24:22 +00:00

49 lines
1.7 KiB
TypeScript

// All configuration comes from environment variables (see .env.example).
import { resolve } from 'node:path';
function int(env: NodeJS.ProcessEnv, name: string, def: number): number {
const raw = env[name];
if (raw === undefined || raw === '') return def;
const n = Number(raw);
if (!Number.isSafeInteger(n) || n < 0) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
return n;
}
export interface Config {
host: string;
port: number;
dataDir: string;
/** built web client; empty = API only (dev, where Vite serves the client) */
staticDir: string;
trustProxy: boolean;
maxPhotoBytes: number;
maxEventBytes: number;
maxGroupBytes: number;
groupCreatePerHour: number;
vapidPublicKey: string;
vapidPrivateKey: string;
vapidSubject: string;
pushEnabled: boolean;
ratesEnabled: boolean;
ratesBaseUrl: string;
}
export function loadConfig(env = process.env): Config {
return {
host: env.HOST || '127.0.0.1',
port: int(env, 'PORT', 8481),
dataDir: resolve(env.DATA_DIR || './data'),
staticDir: env.STATIC_DIR ? resolve(env.STATIC_DIR) : '',
trustProxy: env.TRUST_PROXY === '1',
maxPhotoBytes: int(env, 'MAX_PHOTO_BYTES', 2 * 1024 * 1024),
maxEventBytes: int(env, 'MAX_EVENT_BYTES', 64 * 1024),
maxGroupBytes: int(env, 'MAX_GROUP_BYTES', 200 * 1024 * 1024),
groupCreatePerHour: int(env, 'GROUP_CREATE_PER_HOUR', 10),
vapidPublicKey: env.VAPID_PUBLIC_KEY || '',
vapidPrivateKey: env.VAPID_PRIVATE_KEY || '',
vapidSubject: env.VAPID_SUBJECT || '',
pushEnabled: env.PUSH_DISABLED !== '1',
ratesEnabled: env.RATES_DISABLED !== '1',
ratesBaseUrl: env.RATES_BASE_URL || 'https://www.ecb.europa.eu/stats/eurofxref',
};
}