开发者

Node.js as a forwarding proxy but changing the URL path?

How do i let node.js act as a proxy and forward all requests sent from one server to another server but stripping /couchdb/ from the url path so that for example POST /couchdb/mydatabase will be POST /mydatabase. And when it receives the re开发者_运维百科sponse it should send it to the first server.

All I have done is this (using express) to get all requests where the URL path starts with /couchdb/

app.all(/^\/couchdb\/(?:.)*/, function(req, res) {

});

Could someone guide me through. Thanks


have a look at node-http-proxy. you can use it like this:

  var http = require('http'),
  httpProxy = require('http-proxy');
  httpProxy.createServer(function (req, res, proxy) {
         // Put your custom server logic here (eg rewrite url/header,...)
      proxy.proxyRequest(req, res, {host: 'localhost', port: 9000});
  }).listen(8000);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜