-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use node-http-proxy 1.x to proxy requests to another http server #603
Comments
i figured out the problem. looks like a bug in v1.x. this is similar to what was there in v0.10.x |
@KetanSpeaketh could you give me a gist that I can run that fails? in the specific case you listed with the new api there is no server running that would be able to receive requests in order to proxy appropriately. var http = require('http');
var httpProxy = require('http-proxy');
httpProxy.createProxyServer({
target: {
host: server#2_host,
port: ...
}
}).listen(3000);
// or
var proxy = httpProxy.createProxyServer();
http.createServer(function (req, res) {
// We can do more variable proxying in this case
proxy.web(req, res, {
target: {
host: server#2_host,
port: ...
}
});
}).listen(3001); Both of these should work as expected, otherwise please elaborate on the issue you have. |
@jcrugzz - hey, thanks for responding. gist#1: simple proxy. works as expected. |
So this is actually interesting as it made me go back and read why this is in place. @KetanSpeaketh I recommend giving #529 a read. it seems that this is ONLY the case when you proxy to ANOTHER proxy. For this specific use case, I can add an option (something like |
Hi @jcrugzz,
How would I configure your lib to do the same? The following gists show how this works from outside the corporate proxy and also how routing to local addresses works fine behind the proxy. |
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?
The text was updated successfully, but these errors were encountered: