mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): handle termination signals (#61171)
This commit is contained in:
committed by
GitHub
parent
b80b849058
commit
91e4c05b9f
@@ -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}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user