INNER CODE UNIT · TypeScript
init
marcoturi/fastify-boilerplate · src/index.ts:9
async function init() {
const fastify = Fastify({
logger: {
level: env.log.level,
redact: ['headers.authorization'],
// Attach the request correlation id (from the request-context ALS) to every log line,
// including those from handlers/repositories. Falls back to a sentinel outside a request.
mixin() {
return { correlationId: getRequestId() };
},
},
genReqId: (req) => {
// header best practice: don't use "x-" https://www.rfc-editor.org/info/rfc6648 and keep it lowercase
return (req.headers['request-id'] as string) ?? randomUUID();
},
routerOptions: {
ignoreDuplicateSlashes: true,
},