Fix restify (#88) by only using req.path if a string #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
only use
req.path
if it is a string. this is for restify compatibility; fixes #88.in #29 we preferred
req.path
, becausereq.url
would throw in hapi if the path was invalid.in restify though,
req.path
is a function (which returns a parsed url object). so after #29, restify stopped logging url.in this pr, we check
req.path
to see if it is a string before using it. else we go back to usingreq.url
. alternatively, we could have checked if path was a function, then checked if the object returned had a path element, but simply being more specific about whatreq.path
's we accept was preferred as it reduced the amount of branches the code would take.i have also added a check for
req.url
being undefined, as i nearly hadn't considered that case & almost left the code in a broken/error-throwing state then.req.url.path
side discussion- we could possibly simplify more, see rektide#2 which i am happy to do.
right now, this pr still leaves in an attempt to use
req.url.path
, which was introduced to support hapi a number of years ago. since we now usereq.path
to better/more-safely support hapi (as of #29), we could consider removingreq.url.path
checking: these old checks are redunant. hapi has supportedreq.path
since before 2013's v1.0.0 so no risk there.yet there may be people in the world other than hapi who have grown to expect
req.url.path
. i tend to doubt that, and it's tempting to accept that risk & simplify/drop thereq.url.path
check, but i have left it intact for now. happy to do whatever folks want.