UNPKG

cls-proxify

Version:

Logging on steroids with CLS and Proxy. Integrated with express, koa, fastify.

20 lines (19 loc) 848 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clsProxifyFastifyPlugin = void 0; const consts_1 = require("../consts"); const cls_1 = require("../cls"); exports.clsProxifyFastifyPlugin = (fastify, { proxify }, next) => { fastify.addHook('onRequest', (request, reply, done) => { cls_1.getClsHookedStorage().namespace.bindEmitter(request.raw); cls_1.getClsHookedStorage().namespace.bindEmitter(reply.raw); cls_1.getClsHookedStorage().namespace.run(() => { const proxyValue = proxify(request, reply); cls_1.getClsHookedStorage().set(proxyValue); done(); }); }); next(); }; exports.clsProxifyFastifyPlugin[Symbol.for('skip-override')] = true; exports.clsProxifyFastifyPlugin[Symbol.for('fastify.display-name')] = consts_1.pluginName;