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

Commit 3dae5be

Browse files
committed
Install: Improves code to get proxy.
* Credit: @xzyfer. * Addresses #588.
1 parent a11fafd commit 3dae5be

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

scripts/install.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ function download(url, dest, cb) {
4343
*/
4444

4545
function getProxy() {
46-
var result;
47-
48-
['https-proxy', 'proxy', 'http-proxy'].map(function(config) {
46+
var result = ['https-proxy', 'proxy', 'http-proxy'].filter(function(config) {
4947
var proxy = exec('npm config get ' + config, {silent: true});
5048
var output = proxy.output.trim();
5149

52-
if (proxy.code === 0 && output !== 'undefined' && output !== 'null') {
53-
result = proxy.output;
54-
return;
55-
}
50+
return proxy.code === 0 && validateProxyUrl(output);
5651
});
5752

5853
if (result) {
@@ -63,6 +58,19 @@ function getProxy() {
6358
return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
6459
}
6560

61+
/**
62+
* Validates Proxy URL
63+
*
64+
* @param {String} url
65+
* @api private
66+
*/
67+
68+
function validateProxyUrl(url) {
69+
return output !== 'undefined' &&
70+
output !== 'null' &&
71+
url === require('url').parse(url);
72+
}
73+
6674
/**
6775
* Check if binaries exists
6876
*

0 commit comments

Comments
 (0)