freeCodeCamp/api/src/server.ts
Mrugesh Mohapatra c2e1032e08
Some checks failed
CI - E2E - 3rd party donation tests / Build & Test (20.x) (push) Has been cancelled
CI - Node.js / Lint (20.x) (push) Has been cancelled
CI - Node.js / Build (20.x) (push) Has been cancelled
CI - Node.js / Test (20.x) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 20.x) (push) Has been cancelled
fix(api): logging configs
2025-01-02 19:20:43 +05:30

44 lines
1.1 KiB
TypeScript

// We need to use the triple-slash directive to ensure that ts-node uses the
// reset.d.ts file. It's not possible to import the file directly because it
// is not included in the build (it's a dev dependency).
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./reset.d.ts" />
import { build } from './app';
import {
FREECODECAMP_NODE_ENV,
FCC_API_LOG_LEVEL,
HOST,
PORT
} from './utils/env';
const envToLogger = {
development: {
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname'
}
},
level: FCC_API_LOG_LEVEL || 'info'
},
production: {
level: FCC_API_LOG_LEVEL || 'info'
},
test: undefined
};
const start = async () => {
const fastify = await build({ logger: envToLogger[FREECODECAMP_NODE_ENV] });
try {
const port = Number(PORT);
fastify.log.info(`Starting server on port ${port}`);
await fastify.listen({ port, host: HOST });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
void start();