import { loadEnv, API_HOST, API_PORT } from './lib/env.js'; loadEnv(); const { buildApp } = await import('./app.js'); const { closeDb } = await import('@cancerindex/database'); const app = await buildApp(); const shutdown = async (signal: string) => { app.log.info({ signal }, 'shutting down'); try { await app.close(); await closeDb(); } finally { process.exit(0); } }; process.on('SIGTERM', () => void shutdown('SIGTERM')); process.on('SIGINT', () => void shutdown('SIGINT')); try { await app.listen({ host: API_HOST(), port: API_PORT() }); app.log.info({ docs: `http://${API_HOST()}:${API_PORT()}/v1/docs` }, 'CancerIndex API ready'); } catch (err) { app.log.error({ err }, 'failed to start'); process.exit(1); }