import { loadConfig } from './config'; import { jsonLog, startServer } from './server'; const config = loadConfig(); const app = startServer({ config }); jsonLog('info', 'server started', { port: app.server.port, origin: config.publicOrigin, discord: config.discord !== null }); let stopping = false; const shutdown = async (signal: string) => { if (stopping) return; stopping = true; jsonLog('info', 'shutting down', { signal }); const force = setTimeout(() => process.exit(0), 10_000); await app.stop(); clearTimeout(force); process.exit(0); }; process.on('SIGTERM', () => void shutdown('SIGTERM')); process.on('SIGINT', () => void shutdown('SIGINT')); process.on('uncaughtException', (err) => { jsonLog('error', 'uncaughtException', { err: String(err), stack: err.stack }); process.exit(1); }); process.on('unhandledRejection', (err) => { jsonLog('error', 'unhandledRejection', { err: String(err) }); process.exit(1); });