1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const uuid_1 = require("uuid");
|
4 | const fp = require("fastify-plugin");
|
5 | const logger_session_1 = require("./logger.session");
|
6 | const logger_constants_1 = require("./logger.constants");
|
7 | function requestContext(fastify, opts, next) {
|
8 | fastify.addHook('onRequest', (req, res, done) => {
|
9 | const requestId = req.headers[logger_constants_1.REQUEST_ID_HEADER] || uuid_1.v4();
|
10 | logger_session_1.cls.bindEmitter(req.raw);
|
11 | logger_session_1.cls.bindEmitter(res.res);
|
12 | logger_session_1.cls.runWith(() => {
|
13 | done();
|
14 | }, {
|
15 | [logger_constants_1.REQUEST_INFO]: { requestId }
|
16 | });
|
17 | });
|
18 | next();
|
19 | }
|
20 | exports.requestContextPlugin = fp(requestContext, {
|
21 | fastify: '3.x',
|
22 | name: 'fastify-request-context',
|
23 | });
|
24 |
|
\ | No newline at end of file |