Skip to content

Commit

Permalink
fix: socket null in logger (#3422)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeflyer committed Nov 7, 2021
1 parent 53fe09f commit 692fe4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/logger.js
Expand Up @@ -53,7 +53,7 @@ const serializers = {
version: req.headers['accept-version'],
hostname: req.hostname,
remoteAddress: req.ip,
remotePort: req.socket.remotePort
remotePort: req.socket ? req.socket.remotePort : undefined
}
},
err: pino.stdSerializers.err,
Expand Down
20 changes: 20 additions & 0 deletions test/internals/logger.test.js
Expand Up @@ -112,3 +112,23 @@ test('The logger should error if both stream and file destination are given', t
t.equal(err.message, 'Cannot specify both logger.stream and logger.file options')
}
})

test('The serializer prevent fails if the request socket is undefined', t => {
t.plan(1)

const serialized = loggerUtils.serializers.req({
method: 'GET',
url: '/',
socket: undefined,
headers: {}
})

t.same(serialized, {
method: 'GET',
url: '/',
version: undefined,
hostname: undefined,
remoteAddress: undefined,
remotePort: undefined
})
})

0 comments on commit 692fe4f

Please sign in to comment.