Skip to content

Commit

Permalink
also expose the parsed config
Browse files Browse the repository at this point in the history
  • Loading branch information
emirotin committed May 11, 2017
1 parent 9342469 commit ae95f95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ process.env.http_proxy = 'http:https://10.0.0.1:3129';
globalTunnel.initialize();
```

## Retrieving proxy URL
## Retrieving proxy URL and parsed config

As the module does some extra job determining the proxy (including parsing the environment variables) and does some normalization (like defaulting the protocol to `http:`) it may be useful to retrieve the proxy URL used by the module.

The property `globalTunnel.proxyUrl` is the URL-formatted (including the optional basic auth if provided) proxy config currently in use. It is `null` if the proxy is not currently enabled.

Similarly, the `globalTunnel.proxyConfig` contains the entire parsed and normalized config.

# Compatibility

Any module that doesn't specify [an explicit `agent:` option to
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function stringifyProxy(conf) {

globalTunnel.isProxying = false;
globalTunnel.proxyUrl = null;
globalTunnel.proxyConfig = null;

function findEnvVarProxy() {
var key, val, result;
Expand Down Expand Up @@ -105,6 +106,8 @@ function findEnvVarProxy() {
* (falsy uses node's default).
*/
globalTunnel.initialize = function(conf) {
// don't do anything if already proxying.
// To change the settings `.end()` should be called first.
if (globalTunnel.isProxying) {
return;
}
Expand All @@ -125,8 +128,7 @@ globalTunnel.initialize = function(conf) {
// nothing passed - parse from the env
conf = tryParse(envVarProxy);
} else {
globalTunnel.isProxying = false;
globalTunnel.proxyUrl = null;
// no config - do nothing
return;
}

Expand Down Expand Up @@ -167,6 +169,7 @@ globalTunnel.initialize = function(conf) {

globalTunnel.isProxying = true;
globalTunnel.proxyUrl = stringifyProxy(conf);
globalTunnel.proxyConfig = clone(conf);
} catch (e) {
resetGlobals();
throw e;
Expand Down Expand Up @@ -276,4 +279,5 @@ globalTunnel.end = function() {
resetGlobals();
globalTunnel.isProxying = false;
globalTunnel.proxyUrl = null;
globalTunnel.proxyConfig = null;
};

0 comments on commit ae95f95

Please sign in to comment.