fix(api): handle termination signals (#61171)

This commit is contained in:
Oliver Eyton-Williams
2025-09-16 16:37:09 +02:00
committed by GitHub
parent b80b849058
commit 91e4c05b9f
+11
View File
@@ -5,6 +5,17 @@ import { HOST, PORT } from './utils/env';
const start = async () => { const start = async () => {
const fastify = await build(buildOptions); const fastify = await build(buildOptions);
const stop = async (signal: NodeJS.Signals) => {
fastify.log.info(`Received ${signal}, shutting down.`);
await fastify.close();
fastify.log.info('Shutdown complete');
process.exit(0);
};
process.on('SIGINT', signal => void stop(signal));
process.on('SIGTERM', signal => void stop(signal));
try { try {
const port = Number(PORT); const port = Number(PORT);
fastify.log.info(`Starting server on port ${port}`); fastify.log.info(`Starting server on port ${port}`);