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
This commit is contained in:
agent 2026-10-09 22:24:22 +00:00
parent 1382e53359
commit 04d952872d
11 changed files with 191 additions and 152 deletions

View file

@ -3,6 +3,8 @@
// the service worker fetches and decrypts the actual events itself, so the
// push service never sees content (SPEC.md §7.7).
import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, sign } from 'node:crypto';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import type { PushSub } from './db.ts';
const b64u = (b: Buffer | Uint8Array) => Buffer.from(b).toString('base64url');
@ -35,6 +37,23 @@ export function generateVapidKeys(): { publicKey: string; privateKey: string } {
return { publicKey: b64u(ecdh.getPublicKey()), privateKey: b64u(ecdh.getPrivateKey()) };
}
/**
* VAPID keys from the environment if both are set, otherwise generated once
* and kept in the data directory, so push works without any configuration.
* Deleting vapid.json rotates them (and invalidates every subscription).
*/
export function loadVapidKeys(dataDir: string, envPublic: string, envPrivate: string): { publicKey: string; privateKey: string; source: string } {
if (envPublic && envPrivate) return { publicKey: envPublic, privateKey: envPrivate, source: 'environment' };
const file = join(dataDir, 'vapid.json');
if (existsSync(file)) {
const k = JSON.parse(readFileSync(file, 'utf8'));
if (typeof k.publicKey === 'string' && typeof k.privateKey === 'string') return { ...k, source: file };
}
const k = generateVapidKeys();
writeFileSync(file, JSON.stringify(k), { mode: 0o600, flag: 'wx' });
return { ...k, source: `${file} (new)` };
}
export interface Vapid {
publicKey: string;
privateKey: string;