Connect or Express middleware to modify the response.body

前端 未结 5 1538
一个人的身影
一个人的身影 2020-12-03 02:21

I would like to have a middleware function which modifies the response body.

This is for an express server.

Something like:

function modify(         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 03:14

    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

提交回复
热议问题