From 1dea55d8f2c920721ef6b3ed94c9378115b5081c Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 12 May 2014 15:28:09 +0100 Subject: [PATCH] Check that req.route.path is set --- libraries/metrics/http.coffee | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libraries/metrics/http.coffee b/libraries/metrics/http.coffee index 1f6fe20971..c175f26a14 100644 --- a/libraries/metrics/http.coffee +++ b/libraries/metrics/http.coffee @@ -8,22 +8,24 @@ module.exports.monitor = (logger) -> res.end = () -> end.apply(this, arguments) responseTime = new Date() - startTime - routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1) - key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}" + if req.route?.path? + routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1) + key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}" - Metrics.timing(key, responseTime) - logger.log - req: - url: req.originalUrl || req.url - method: req.method - referrer: req.headers['referer'] || req.headers['referrer'] - "remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress - "user-agent": req.headers["user-agent"] - "content-length": req.headers["content-length"] - res: - "content-length": res._headers?["content-length"] - statusCode: res.statusCode - "response-time": responseTime - "http request" + Metrics.timing(key, responseTime) + logger.log + req: + url: req.originalUrl || req.url + method: req.method + referrer: req.headers['referer'] || req.headers['referrer'] + "remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress + "user-agent": req.headers["user-agent"] + "content-length": req.headers["content-length"] + res: + "content-length": res._headers?["content-length"] + statusCode: res.statusCode + "response-time": responseTime + "http request" + next()