开发者

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

开发者 https://www.devze.com 2023-02-09 18:05 出处:网络
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

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

精彩评论

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