31 lines
846 B
TypeScript
31 lines
846 B
TypeScript
import { buildApp } from './app.js';
|
|
import { loadConfig } from './config.js';
|
|
|
|
const config = loadConfig();
|
|
const app = await buildApp({ config });
|
|
|
|
let shuttingDown = false;
|
|
const shutdown = (signal: string) => {
|
|
if (shuttingDown) return;
|
|
shuttingDown = true;
|
|
const timeout = setTimeout(() => {
|
|
app.log.error({ signal }, 'graceful shutdown timed out');
|
|
process.exit(1);
|
|
}, 10_000);
|
|
timeout.unref();
|
|
void app
|
|
.close()
|
|
.then(() => {
|
|
clearTimeout(timeout);
|
|
process.exit(0);
|
|
})
|
|
.catch((error: unknown) => {
|
|
clearTimeout(timeout);
|
|
app.log.error({ err: error, signal }, 'graceful shutdown failed');
|
|
process.exit(1);
|
|
});
|
|
};
|
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
|
|
await app.listen({ host: '0.0.0.0', port: config.PORT });
|