Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Install: Improves code to get proxy.
Browse files Browse the repository at this point in the history
* Credit: @xzyfer.
* Addresses #588.
  • Loading branch information
am11 committed Jan 8, 2015
1 parent a11fafd commit 6539e7b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,11 @@ function download(url, dest, cb) {
*/

function getProxy() {
var result;

['https-proxy', 'proxy', 'http-proxy'].map(function(config) {
var result = ['https-proxy', 'proxy', 'http-proxy'].filter(function(config) {
var proxy = exec('npm config get ' + config, {silent: true});
var output = proxy.output.trim();

if (proxy.code === 0 && output !== 'undefined' && output !== 'null') {
result = proxy.output;
return;
}
});
return proxy.code === 0 && validateProxyUrl(proxy.output.trim());
})[0];

if (result) {
return result;
Expand All @@ -63,6 +57,24 @@ function getProxy() {
return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
}

/**
* Validates Proxy URL
*
* @param {String} url
* @api private
*/

function validateProxyUrl(url) {
if (/\n/.test(url)) {
url = url.replace(/\r?\n+/, '\n').split('\n');
url = url[url.length - 3].trim(); // get the second last element.
}

return url !== 'null' &&
url !== 'undefined' &&
url === require('url').parse(url);
}

/**
* Check if binaries exists
*
Expand Down

0 comments on commit 6539e7b

Please # to comment.