Skip to content
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

Create proxy server behind corporate proxy #832

Open
ahmedabbas11 opened this issue May 27, 2015 · 5 comments
Open

Create proxy server behind corporate proxy #832

ahmedabbas11 opened this issue May 27, 2015 · 5 comments

Comments

@ahmedabbas11
Copy link

i have anodejs application that uses http-proxy to create a proxy to send the incoming requests for example: https://localhost/api/login to https://server1/api/login. here is the code used :

var httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer();

self.routes['/api/*'] = function(req, res) {
proxy.proxyRequest(req, res,
{
target: "https://server1",
changeOrigin: true
});
};
this is working just fine in my machine.
Now when i deploy this on a server, i get error
{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
the problem is that there is another proxy let say (corporate proxy let call it: localProxy) between myserver and server1.
I don't know where to set the localProxy in my code above. and where to set the server1 url?
and is there is a way to use http-proxy in this case

@alfonso-presa
Copy link

If you are using HTTPS, wich it seems so, you should use https-proxy-agent. You can provide a proxy server to https-proxy-agent:

var HttpsProxyAgent = require('https-proxy-agent');
var proxyServer = process.env.http_proxy;

var proxy = httpProxy.createProxyServer({
agent: new HttpsProxyAgent(proxyServer)
});

@colthreepv
Copy link

Great suggestion, it works.

@barroudjo
Copy link

I agree, this should be the go-to solution when one wants to use node-http-proxy to send requests through another proxy.

@yckbilly1929
Copy link

If you are using HTTPS, wich it seems so, you should use https-proxy-agent. You can provide a proxy server to https-proxy-agent:

var HttpsProxyAgent = require('https-proxy-agent'); var proxyServer = process.env.http_proxy;

var proxy = httpProxy.createProxyServer({ agent: new HttpsProxyAgent(proxyServer) });

this solution saves my day 8 years after 😆

@davidshen84
Copy link

Thansk @alfonso-presa !

By any chance this knowledge can be added to the documentation? The description for target, agent and forward are very vague. Unless you are very familiar with the code, it is unlikely you can connect these options together and understand when to use which.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants