@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
25 lines (24 loc) • 901 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapHandler = wrapHandler;
/* eslint-disable prefer-rest-params */
const Context_1 = require("../../agent/Context");
const contextFromRequest_1 = require("./contextFromRequest");
function wrapHandler(handler) {
return function wrapped() {
if (arguments.length > 0 && !isFastifyRequest(arguments[0])) {
return handler.apply(
// @ts-expect-error We don't know the type of this
this, arguments);
}
const context = (0, contextFromRequest_1.contextFromRequest)(arguments[0]);
return (0, Context_1.runWithContext)(context, () => {
return handler.apply(
// @ts-expect-error We don't know the type of this
this, arguments);
});
};
}
function isFastifyRequest(req) {
return typeof req === "object";
}