Skip to content

Conversation

BernhardRode
Copy link

Handle toProxy option properly and get proxy settings from environment.

There is an option toProxy (true/false) for http-proxy. But it is never used afaiks.
This fix checks the option and uses the http/https proxy set in the environment variables.

Usage:

{ "/api": { "target": "http://upstreamserver.net", "toProxy": true } } 

Sorry, for I had no time for unit tests (just needed a local hotfix ;) )... If you like the solution I could into this PR in more detail during the weekend.

Handle toProxy option properly and get proxy settings from environment.
@assiomatica
Copy link

Hi,

I have tested your patch, as is it's not working, below the correct code:

`if (options.toProxy) {
var upstreamProxyServer;
if (typeof options.toProxy === 'boolean') {
upstreamProxyServer = url.parse(
isSSL.test(options[forward || 'target'].protocol) ? process.env['https_proxy'] || '' : process.env['http_proxy'] || ''
);
} else {
upstreamProxyServer = url.parse(options.toProxy);
}

if (upstreamProxyServer) { outgoing.path = options[forward || 'target'].protocol + '//' + outgoing.host + outgoing.path; outgoing.host = upstreamProxyServer.host; outgoing.hostname = upstreamProxyServer.hostname; outgoing.port = upstreamProxyServer.port; } 

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants