Skip to content

Commit

Permalink
update ignorePaths logic (#72)
Browse files Browse the repository at this point in the history
According to the hapi 18 release notes, request.url.path has
gone away in favor of request.path or request.url.pathname.
The same release notes also state that request.url.pathname
has not changed.

Refs: hapijs/hapi#3871
  • Loading branch information
cjihrig authored and mcollina committed Feb 8, 2019
1 parent 11a6235 commit d50a867
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function register (server, options) {

// set a logger for each request
server.ext('onRequest', (request, h) => {
if (options.ignorePaths && ignoreTable[request.url.path]) {
if (options.ignorePaths && ignoreTable[request.url.pathname]) {
request.logger = nullLogger
return h.continue
}
Expand Down Expand Up @@ -106,7 +106,7 @@ async function register (server, options) {

// log when a request completes
tryAddEvent(server, options, 'on', 'response', function (request) {
if (options.ignorePaths && ignoreTable[request.url.path]) {
if (options.ignorePaths && ignoreTable[request.url.pathname]) {
return
}

Expand Down
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ experiment('ignore request logs for paths in ignorePaths', () => {
resolver = resolve
})
const stream = sink((data) => {
expect(data.req.url).to.not.equal('/ignored')
expect(data.req.url).to.endWith('/foo')
resolver()
})
const logger = require('pino')(stream)
Expand All @@ -1022,7 +1022,7 @@ experiment('ignore request logs for paths in ignorePaths', () => {

await server.inject({
method: 'PUT',
url: '/'
url: '/foo'

})
await done
Expand All @@ -1037,8 +1037,8 @@ experiment('ignore response logs for paths in ignorePaths', () => {
resolver = resolve
})
const stream = sink((data) => {
expect(data.req.url).to.endWith('/foo')
expect(data.msg).to.equal('request completed')
expect(data.req.url).to.not.equal('/ignored')
resolver()
})
const logger = require('pino')(stream)
Expand All @@ -1060,7 +1060,7 @@ experiment('ignore response logs for paths in ignorePaths', () => {

await server.inject({
method: 'PUT',
url: '/'
url: '/foo'

})
await done
Expand Down

0 comments on commit d50a867

Please sign in to comment.