连接或快速中间件来修改response.body [英] Connect or Express middleware to modify the response.body
本文介绍了连接或快速中间件来修改response.body的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个修改响应正文的中间件功能。
I would like to have a middleware function which modifies the response body.
这是一个快速服务器。
如下所示:
function modify(req, res, next){
res.on('send', function(){
res.body = res.body + "modified"
});
next();
}
express.use(modify);
我不明白要听什么事件。任何帮助或文档都将被欣赏。
I don't understand what event to listen for. Any help or documentation would be appreciate.
推荐答案
您不需要听任何事件。只需使它
You don't need to listen to any events. Just make it
function modify(req, res, next){
res.body = res.body + "modified";
next();
}
和使用
在你使用
路由器之后。在所有路由执行完毕后,您可以修改机身
And use
it after you use
the router. This way after all your routes have executed you can modify the body
这篇关于连接或快速中间件来修改response.body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文