Express.js- add response body

后端 未结 2 2015
醉话见心
醉话见心 2021-02-14 17:34

I would like to add a body property to Express.js\' response object, which will be called every time the send method is called, I do it by adding the f

2条回答
  •  一整个雨季
    2021-02-14 18:08

    You are probably using something like this:

    res.send({ foo : 'bar' });
    

    In other words, you're passing an object to res.send.

    This will do the following:

    • call res.send with the object as argument
    • res.send checks the argument type and sees that it's an object, which it passed to res.json
    • res.json converts the object to a JSON string, and calls res.send again, but this time with the JSON string as argument

提交回复
热议问题