import './config/env.js'; import { startApi, stopApi } from './api/index.js'; import { closeDb } from './db/client.js'; import { closePool } from './db/mssqlClient.js'; async function shutdown() { await stopApi(); try { closeDb(); await closePool(); } catch (error) { console.error('Failed to close database:', error); process.exitCode = 1; } } process.on('SIGINT', () => { shutdown().then(() => process.exit(0)); }); process.on('SIGTERM', () => { shutdown().then(() => process.exit(0)); }); startApi().catch((err) => { console.error('Failed to start API:', err.message); process.exit(1); });