express.js - how to intercept response.send() / response.json()

后端 未结 4 2160
我寻月下人不归
我寻月下人不归 2020-12-08 14:57

Lets say I have multiple places where I call response.send(someData). Now I want to create a single global interceptor where I catch all .send meth

4条回答
  •  温柔的废话
    2020-12-08 15:15

    You can simply do it using NODEJS and Express, say you are calling an API and want to send modify the data before sending response back.

    router.get('/id', (req,res) => {
    ... //your code here filling DATA
    
      let testData = {
        "C1": "Data1",
        "C2": "Data2",
        "yourdata": DATA
      };          
      res.send(testData);
    });
    

提交回复
热议问题