// Boot: open the index, start the ingest, serve. import { config } from './config.js'; import { openDb } from './db.js'; import { createIdentity } from './identity.js'; import { createIngest } from './ingest.js'; import { createApp } from './app.js'; const log = (...a) => console.log(new Date().toISOString(), ...a); const db = openDb(config.dataDir); const identity = createIdentity(config); const ingest = createIngest({ db, config, identity }); const app = createApp({ db, config, identity, ingest, log }); const server = app.listen(config.port, () => { log(`appmosphe.re listening on :${config.port} (${config.publicUrl}), data in ${config.dataDir}`); ingest.start().catch((err) => log('ingest failed to start:', err.stack || err.message)); }); let closing = false; async function shutdown(signal) { if (closing) return; closing = true; log(`${signal}: shutting down`); server.close(); try { await ingest.stop(); } catch { /* already gone */ } db.close(); process.exit(0); } process.on('SIGTERM', () => shutdown('SIGTERM')); process.on('SIGINT', () => shutdown('SIGINT'));