问题描述
我需要使用 Express 拦截响应的状态和正文。
我想用一个中间件来处理这个问题,并且看到了这些完美运行的代码行:
app.use((req,res,next) => {
let oldSend = res.send
res.send = function(data) {
console.log(data) // do something with the data
res.send = oldSend // set function back to avoid the 'double-send'
return res.send(data) // just call as normal with data
}
next() })
我是 Node.js 的新手,并不太了解在这个中间件期间发生了什么。 我试图通过以下方式捕捉状态:
app.use((req,next) => {
let oldStatus = res.status
res.status= function(data) {
console.log(data) // do something with the data
res.status= oldStatus // set function back to avoid the 'double-send'
return res.status(data) // just call as normal with data
}
next() })
它也很好用,但现在我想获取状态和正文但不知道该怎么做...
提前谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)