From 79c9241cbcde5a764f3917ff22f28a54f5ccce99 Mon Sep 17 00:00:00 2001 From: rektide de la faye Date: Tue, 22 Feb 2022 14:56:29 -0500 Subject: [PATCH] call req.path() if a function. restify compat, fixes #88 in #29 we preferred req.path, because req.url would throw in hapi if the path was invalid. in restify though, req.path is a function, and this change made the url no longer log. check req.path to see if it is a function, and invoke it if it is. --- lib/req.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/req.js b/lib/req.js index 85264d0..7d385b3 100644 --- a/lib/req.js +++ b/lib/req.js @@ -73,9 +73,12 @@ function reqSerializer (req) { _req.url = req.originalUrl _req.query = req.query _req.params = req.params + } else if (req.path) { + // req.path is to make hapi safe with invalid paths. req.path() is for restify compat. + _req.url = typeof req.path === 'function' ? req.path() : req.path } else { // req.url.path is for hapi compat. - _req.url = req.path || (req.url ? (req.url.path || req.url) : undefined) + _req.url = req.url ? (req.url.path || req.url) : undefined } _req.headers = req.headers _req.remoteAddress = connection && connection.remoteAddress