如何使用 nodejs 将 client/user 从一台服务器反向代理到另一台服务器?

how to reverse-proxy a client/user from one server to another using nodejs?

我一直在寻找一种方法,通过使用 POST请求

apiRoutes.post('/route', function(req, res) {
res.json({ message: 'Done' });
  var tunroute=req.body.address;
  console.log(tunroute);

   //{tunroute contains the address i.e 10.0.0.1:300}

   //{ here is where i want to proxy to server at 10.0.0.1:300 }

});

请帮忙!!

所以我找到了答案, 我用了

http-proxy-middleware

用于从一台服务器到另一台服务器的反向代理客户端

这是相同的代码。

var express = require('express');
var app = express();
var proxy = require('http-proxy-middleware');
var methodOverride = require('method-override');
var target = ['http://www.facebook.com',
              'http://10.0.0.1:3000',
              'http://127.0.0.1']

  app.use(methodOverride());

  app.get('/change',function(req,res){

    options = {
            target: target[2],      // target host
            changeOrigin: false,    // needed for virtual hosted sites
            ws: true,               // proxy websockets
        };
    var = exampleProxy = proxy(options);

    app.use('/', exampleProxy);

    return res.redirect("./");
  });

  app.listen(3000);