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) => {
|
2017-12-18 15:12:44 +01:00
|
|
|
const { pathname } = url.parse(req.originalUrl);
|
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,
|
|
|
|
statusCode: res.statusCode,
|
|
|
|
time,
|
|
|
|
};
|
|
|
|
config.eventBus.emit(REQUEST_TIME, timingInfo);
|
|
|
|
});
|
|
|
|
};
|