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 response 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With