1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

fix: stop measure responsetime for unknown paths (#591)

This commit is contained in:
Ivar Conradi Østhus 2020-04-30 23:04:06 +02:00 committed by GitHub
parent 924edc8109
commit 7599553a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -5,10 +5,12 @@ const url = require('url');
module.exports = function(config) {
const logger = config.getLogger('HTTP');
return (req, res, next) => {
next();
if (config.enableRequestLogger) {
const { pathname } = url.parse(req.originalUrl);
logger.info(`${res.statusCode} ${req.method} ${pathname}`);
res.on('finish', () => {
const { pathname } = url.parse(req.originalUrl);
logger.info(`${res.statusCode} ${req.method} ${pathname}`);
});
}
next();
};
};

View File

@ -6,11 +6,15 @@ const { REQUEST_TIME } = require('../events');
module.exports = function(config) {
return responseTime((req, res, time) => {
const { pathname } = url.parse(req.originalUrl);
const { statusCode } = res;
const pathname = req.route
? url.parse(req.originalUrl).pathname
: '(hidden)';
const timingInfo = {
path: pathname,
method: req.method,
statusCode: res.statusCode,
statusCode,
time,
};
config.eventBus.emit(REQUEST_TIME, timingInfo);