gpt4 book ai didi

node.js - Morgan Logging - 是否可以从请求 header 记录用户名?如何?

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:13 25 4
gpt4 key购买 nike

app.use(morgan(function (tokens, req, res) {
console.log(req)
try {
let logData = {
morganLogStream: [
tokens['date'](req, res),
' Type-', tokens.method(req, res, 'Type'),
' Url-', tokens.url(req, res).split('?')[0],
' Status-', tokens.status(req, res),
' Content_Length-', tokens.res(req, res, 'content-length'),
' Response_Time-', tokens['response-time'](req, res), 'ms',
].join('')
}

}))

我正在使用带有 kerberos 的基本身份验证。我可以看到授权 header ,但无法获取该值。

最佳答案

我能做的最好的是:

new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString('ascii').split(':')[0] : ''

返回用户名。我希望 morgan 图书馆有任何直接选择。

关于node.js - Morgan Logging - 是否可以从请求 header 记录用户名?如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53107689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com