2017-11-16 15:41:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-18 15:12:44 +01:00
|
|
|
const url = require('url');
|
2017-11-16 15:41:33 +01:00
|
|
|
const responseTime = require('response-time');
|
|
|
|
const { REQUEST_TIME } = require('../events');
|
|
|
|
|
|
|
|
module.exports = function(config) {
|
|
|
|
return responseTime((req, res, time) => {
|
2020-04-30 23:04:06 +02:00
|
|
|
const { statusCode } = res;
|
|
|
|
const pathname = req.route
|
|
|
|
? url.parse(req.originalUrl).pathname
|
|
|
|
: '(hidden)';
|
|
|
|
|
2017-11-16 15:41:33 +01:00
|
|
|
const timingInfo = {
|
2017-12-18 15:12:44 +01:00
|
|
|
path: pathname,
|
2017-11-16 15:41:33 +01:00
|
|
|
method: req.method,
|
2020-04-30 23:04:06 +02:00
|
|
|
statusCode,
|
2017-11-16 15:41:33 +01:00
|
|
|
time,
|
|
|
|
};
|
|
|
|
config.eventBus.emit(REQUEST_TIME, timingInfo);
|
|
|
|
});
|
|
|
|
};
|