1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/middleware/response-time.js

23 lines
577 B
JavaScript
Raw Normal View History

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