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:
parent
924edc8109
commit
7599553a90
@ -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();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user