MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / start

Function start

api/src/server.ts:6–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { HOST, PORT } from './utils/env.js';
5
6const start = async () => {
7 const fastify = await build(buildOptions);
8
9 const stop = async (signal: NodeJS.Signals) => {
10 fastify.log.info(`Received ${signal}, shutting down.`);
11
12 fastify.server.closeAllConnections();
13 await new Promise<void>(resolve => {
14 fastify.server.close(() => resolve());
15 });
16
17 // Yield one tick so libuv can finalize uv_close() on the TCP handle
18 // before pino's autoEnd blocks the event loop via Atomics.wait().
19 await new Promise<void>(resolve => setImmediate(resolve));
20
21 await fastify.close();
22 process.exit(0);
23 };
24
25 process.on('SIGINT', signal => void stop(signal));
26 process.on('SIGTERM', signal => void stop(signal));
27
28 try {
29 await fastify.listen({ port: Number(PORT), host: HOST });
30 } catch (err) {
31 fastify.log.error(err);
32 process.exit(1);
33 }
34};
35
36void start();

Callers 1

server.tsFile · 0.85

Calls 2

buildFunction · 0.85
stopFunction · 0.85

Tested by

no test coverage detected