proxy json requests with node express

后端 未结 3 1756
深忆病人
深忆病人 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:48

    app.use('/api', function(req, res) {
      var url = 'http://my.domain.com/api' + req.url;
      
      request({
              uri: url,
              method: "POST",
              body: _body,
              json: true
          }, function (_err, _res, _resBody) {
              //do somethings
              res.json(_resBody);
          });
    
    });

提交回复
热议问题