Skip to content

Commit

Permalink
added getProxy (#3320)
Browse files Browse the repository at this point in the history
* added getProxy

getProxy checks proxy settings from process.env.https_proxy or Yarn (NPM) config (.npmrc)

* changed yarn for npm to get https-proxy 

default value for https-proxy is null, not undefined like in yarn
  • Loading branch information
mdogadailo authored and gaearon committed Jan 9, 2018
1 parent 887fd10 commit 3a0b836
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,21 @@ function isSafeToCreateProjectIn(root, name) {
return false;
}

function getProxy() {
if (process.env.https_proxy) {
return process.env.https_proxy;
} else {
try {
// Trying to read https-proxy from .npmrc
let httpsProxy = execSync('npm config get https-proxy')
.toString()
.trim();
return httpsProxy !== 'null' ? httpsProxy : undefined;
} catch (e) {
return;
}
}
}
function checkThatNpmCanReadCwd() {
const cwd = process.cwd();
let childOutput = null;
Expand Down Expand Up @@ -709,10 +724,11 @@ function checkIfOnline(useYarn) {

return new Promise(resolve => {
dns.lookup('registry.yarnpkg.com', err => {
if (err != null && process.env.https_proxy) {
let proxy;
if (err != null && (proxy = getProxy())) {
// If a proxy is defined, we likely can't resolve external hostnames.
// Try to resolve the proxy name as an indication of a connection.
dns.lookup(url.parse(process.env.https_proxy).hostname, proxyErr => {
dns.lookup(url.parse(proxy).hostname, proxyErr => {
resolve(proxyErr == null);
});
} else {
Expand Down

0 comments on commit 3a0b836

Please sign in to comment.