First commit
This commit is contained in:
47
node_modules/pino-std-serializers/lib/res.js
generated
vendored
Normal file
47
node_modules/pino-std-serializers/lib/res.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
mapHttpResponse,
|
||||
resSerializer
|
||||
}
|
||||
|
||||
const rawSymbol = Symbol('pino-raw-res-ref')
|
||||
const pinoResProto = Object.create({}, {
|
||||
statusCode: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: 0
|
||||
},
|
||||
headers: {
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
value: ''
|
||||
},
|
||||
raw: {
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
return this[rawSymbol]
|
||||
},
|
||||
set: function (val) {
|
||||
this[rawSymbol] = val
|
||||
}
|
||||
}
|
||||
})
|
||||
Object.defineProperty(pinoResProto, rawSymbol, {
|
||||
writable: true,
|
||||
value: {}
|
||||
})
|
||||
|
||||
function resSerializer (res) {
|
||||
const _res = Object.create(pinoResProto)
|
||||
_res.statusCode = res.headersSent ? res.statusCode : null
|
||||
_res.headers = res.getHeaders ? res.getHeaders() : res._headers
|
||||
_res.raw = res
|
||||
return _res
|
||||
}
|
||||
|
||||
function mapHttpResponse (res) {
|
||||
return {
|
||||
res: resSerializer(res)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user