Add server: encrypted event log API, blobs, SSE, ECB rates, Web Push
Node 24 standard library only (node:http, node:sqlite, node:crypto). Push uses VAPID + RFC 8291 encryption with an allowlist of push services. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
This commit is contained in:
parent
c2043b86bc
commit
8dd25b93b0
10 changed files with 1005 additions and 1 deletions
47
apps/server/src/config.ts
Normal file
47
apps/server/src/config.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// All configuration comes from environment variables (see deploy/.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;
|
||||
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 || '',
|
||||
ratesEnabled: env.RATES_DISABLED !== '1',
|
||||
ratesBaseUrl: env.RATES_BASE_URL || 'https://www.ecb.europa.eu/stats/eurofxref',
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue