UNPKG

restifyx.js

Version:

Advanced API endpoint handler system with automatic documentation

31 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupEndpointContext = setupEndpointContext; const logger_1 = require("../utils/logger"); /** * Middleware that sets up the context for endpoint handlers * * @param req - Express request * @param res - Express response * @param next - Express next function */ function setupEndpointContext(req, res, next) { const logger = (0, logger_1.getLogger)(); try { global.CURRENT_REQUEST = req; global.CURRENT_RESPONSE = res; const originalEnd = res.end; res.end = function (chunk, encoding, cb) { delete global.CURRENT_REQUEST; delete global.CURRENT_RESPONSE; return originalEnd.call(this, chunk, encoding, cb); }; logger.debug("Endpoint context set up successfully"); next(); } catch (error) { logger.error("Error setting up endpoint context", { error }); next(error); } } //# sourceMappingURL=EndpointHandler.js.map