Repository Public
1/** Server-side configuration. Never import this from a client component. */2import path from "node:path";34function req(name: string): string {5 const v = process.env[name];6 if (!v) throw new Error(`Missing environment variable ${name}`);7 return v;8}9const opt = (name: string) => process.env[name] || undefined;10const num = (name: string, def: number) => { const v = opt(name); if (!v) return def; const n = Number(v); if (!Number.isFinite(n) || n < 0) throw new Error(`${name} must be a positive number`); return n; };11const MB = 1024 * 1024;1213export const env = {14 get databaseUrl() { return req("DATABASE_URL"); },15 /** Public origin of the site. WebAuthn's expected origin and its RP ID derive from it. */16 get appUrl() { return (opt("APP_URL") ?? "http://localhost:8700").replace(/\/$/, ""); },17 /** WebAuthn RP ID: the site's host name (sheet.spboucher.ai in production, localhost in development). */18 get rpId() { return opt("WEBAUTHN_RP_ID") ?? new URL(this.appUrl).hostname; },19 /** Signs preview links and internal render tokens. */20 get appSecret() { const s = req("APP_SECRET"); if (s.length < 32) throw new Error("APP_SECRET must be at least 32 characters"); return s; },21 get isProd() { return process.env.NODE_ENV === "production"; },22 get adminEmail() { return opt("ADMIN_EMAIL"); },23 get adminName() { return opt("ADMIN_NAME") ?? "Simon-Pierre Boucher"; },2425 // Claude. The key exists only in the server environment; it is never stored in the database or sent to a browser.26 get anthropicApiKey() { return opt("ANTHROPIC_API_KEY"); },27 /** Default model until the administrator picks one in the settings (validated against the live model list). */28 get anthropicDefaultModel() { return opt("ANTHROPIC_MODEL") ?? "claude-opus-5-5"; },2930 // Storage of uploads and exports (never under public/).31 get storageDriver() { return opt("STORAGE_DRIVER") ?? "local"; },32 get storageRoot() { return path.resolve(/*turbopackIgnore: true*/ req("STORAGE_ROOT")); },33 get maxUploadBytes() { return num("UPLOAD_MAX_MB", 20) * MB; },34 get storageQuotaBytes() { return num("STORAGE_QUOTA_GB", 5) * 1024 * MB; },35 /** clamd socket (unix path) or host:port. Empty = uploads are stored as "unscanned" and the studio says so. */36 get clamd() { return opt("CLAMD_SOCKET"); },3738 /** Base URL the worker's headless browser opens to render exports (the web process, loopback). */39 get internalUrl() { return (opt("INTERNAL_URL") ?? `http://127.0.0.1:${process.env.PORT ?? 8700}`).replace(/\/$/, ""); },40 get chromiumPath() { return opt("CHROMIUM_PATH"); },4142 get backupDir() { return opt("BACKUP_DIR"); },43 get logLevel() { return opt("LOG_LEVEL") ?? "info"; },44};45