1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-19 00:15:43 +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) { module.exports = function(config) {
const logger = config.getLogger('HTTP'); const logger = config.getLogger('HTTP');
return (req, res, next) => { return (req, res, next) => {
next();
if (config.enableRequestLogger) { if (config.enableRequestLogger) {
const { pathname } = url.parse(req.originalUrl); res.on('finish', () => {
logger.info(`${res.statusCode} ${req.method} ${pathname}`); 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) { module.exports = function(config) {
return responseTime((req, res, time) => { 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 = { const timingInfo = {
path: pathname, path: pathname,
method: req.method, method: req.method,
statusCode: res.statusCode, statusCode,
time, time,
}; };
config.eventBus.emit(REQUEST_TIME, timingInfo); config.eventBus.emit(REQUEST_TIME, timingInfo);