Use node-http-proxy 1.x to proxy requests to another http server
Created by: ketan-vijayvargiya
Hello, My use-case is this: I have a proxy server running in Nodejs (created using httpProxy.createProxyServer. call it server#1). There is another proxy-server (squid-based. call it server#2) to which server#1 should proxy requests to. So basically, clients will use my server#1 as proxy for their website calls. server#1 will in turn proxy request to server#2. server#2 will actually call the requested domain and send response back to client via server#1.
I could do this in node-http-proxy v0.x by: var httpProxy = require('http-proxy') var proxy = new httpProxy.RoutingProxy(); httpProxy.createServer( function (request, response, proxy) { // blah blah proxy.proxyRequest( request, response, { host : server#2_host, port: ... } ); });
How to achieve this in node-http-proxy 1.x is the question? I expected this to work, but it doesn't: var proxy = httpProxy.createProxyServer({target: { host: server#2_host, port: ... }}); proxy.web(req, res);
Any pointers on how I can do this?