我用快递,我想审计响应后,我把它快速响应体之后发送
var app = express();
app.use(audit.auditRequest); // working fine
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(expressValidator({
customValidators: validations.customValidators,
customSanitizers: sanitizers.customSanitizers
}));
app.use(auth.authenticate);
app.use('/myPath', myPathHandler);
app.use(errorHandler.handleErrors);
**app.use(audit.auditResponse);**
的ErrorHandler,例如,看起来是这样的:
...
res.status(500).send({ message : "abc", code: 5010, description : "def" });
next(); // call audit middleware
,然后审计中间件看起来像这样:
...
auditModule.auditResponse = function auditResponse(req, res, next) {
auditLogger.info('Response', res.body);
// but res.body is undefined
};
...
任何想法为什么?
你是不是指'req.body'? – Iceman
不,我需要记录我发送给用户的响应 –
把完整的代码放在这里。 – Iceman