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