Repository Public
1import path from "node:path"23const env = process.env4function req(name: string, fallback?: string): string {5 const v = env[name] ?? fallback6 if (v === undefined || v === "") throw new Error(`Missing environment variable ${name}`)7 return v8}910export const config = {11 port: Number(env.PORT ?? 8720),12 host: env.HOST ?? "127.0.0.1",13 databaseUrl: req("DATABASE_URL", "postgres://127.0.0.1/sp_message_dev"),14 origin: req("SPM_ORIGIN", "http://localhost:8720"),15 rpId: req("SPM_RP_ID", "localhost"),16 rpName: "SP Message",17 dataDir: path.resolve(env.SPM_DATA_DIR ?? "./.data"),18 webDir: path.resolve(env.SPM_WEB_DIR ?? "./dist/web"),19 trustProxy: (env.SPM_TRUST_PROXY ?? "127.0.0.1").split(",").map((s) => s.trim()).filter(Boolean),20 turnUrls: (env.SPM_TURN_URLS ?? "").split(",").map((s) => s.trim()).filter(Boolean),21 turnSecret: env.SPM_TURN_SECRET ?? "",22 appleAppIds: (env.SPM_APPLE_APP_IDS ?? "").split(",").map((s) => s.trim()).filter(Boolean),23 sessionIdleDays: 14,24 sessionMaxDays: 60,25 messageRetentionDays: Number(env.SPM_MESSAGE_RETENTION_DAYS ?? 90),26 transientRetentionHours: 6,27 maxChunkBytes: 4 * 1024 * 1024 + 64,28 maxFileBytes: Number(env.SPM_MAX_FILE_BYTES ?? 4 * 1024 * 1024 * 1024),29 secureCookies: (env.SPM_ORIGIN ?? "").startsWith("https://"),30}31export const cookieName = config.secureCookies ? "__Host-spm_session" : "spm_session"32