proxy json requests with node express

后端 未结 3 1734
深忆病人
深忆病人 2021-01-13 08:44

I use the following node-express code to proxy requests from a web server to an API server:

app.use(\'/api\', function(req, res) {
  var url = \'http://my.do         


        
3条回答
  •  有刺的猬
    2021-01-13 09:23

    In the case of a post request, the following construct works:

    app.post('/api/method', (req, res) => {
      req.pipe(request.post(someUrl, { json: true, body: req.body }), { end: false }).pipe(res);
    }
    

    This is of course relevant if you're using the bodyparser middleware.

提交回复
热议问题