Skip to content

Commit

Permalink
call req.path() if a function. restify compat, fixes pinojs#88
Browse files Browse the repository at this point in the history
in pinojs#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.
  • Loading branch information
rektide committed Feb 22, 2022
1 parent ed85319 commit 79c9241
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/req.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 79c9241

Please # to comment.