From 235739ef7cf45e28b4e3c6ab38e0bdbbfe4ad2e7 Mon Sep 17 00:00:00 2001 From: Ben Sykes Date: Wed, 2 Aug 2017 09:45:15 -0700 Subject: [PATCH 1/2] Adjust the `checkIfOnline` check if in a corporate proxy environment If the environment variable `https_proxy` is set, test that the proxy name is resolveable rather than 'registry.yarnpkg.com'. This fixes #2832. --- packages/create-react-app/createReactApp.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 07b083a5f62..b2f2d01baee 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -47,6 +47,7 @@ const semver = require('semver'); const dns = require('dns'); const tmp = require('tmp'); const unpack = require('tar-pack').unpack; +const url = require('url'); const hyperquest = require('hyperquest'); const packageJson = require('./package.json'); @@ -613,7 +614,13 @@ function checkIfOnline(useYarn) { } return new Promise(resolve => { - dns.lookup('registry.yarnpkg.com', err => { + let host = 'registry.yarnpkg.com'; + // If a proxy is defined, we likely can't resolve external hostnames. + // Try to resolve the proxy name as an indication of a connection. + if (process.env.https_proxy) { + host = url.parse(process.env.https_proxy).hostname; + } + dns.lookup(host, err => { resolve(err === null); }); }); From 99c4ab1c9ae69f201c79b0f5274e5129dacc7d04 Mon Sep 17 00:00:00 2001 From: Ben Sykes Date: Sat, 5 Aug 2017 21:18:17 -0700 Subject: [PATCH 2/2] Adjust to check yarnpkg.com first, then check the proxy address only if that failed --- packages/create-react-app/createReactApp.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index b2f2d01baee..4fbb761d4bb 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -614,14 +614,16 @@ function checkIfOnline(useYarn) { } return new Promise(resolve => { - let host = 'registry.yarnpkg.com'; - // If a proxy is defined, we likely can't resolve external hostnames. - // Try to resolve the proxy name as an indication of a connection. - if (process.env.https_proxy) { - host = url.parse(process.env.https_proxy).hostname; - } - dns.lookup(host, err => { - resolve(err === null); + dns.lookup('registry.yarnpkg.com', err => { + if (err != null && process.env.https_proxy) { + // 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 => { + resolve(proxyErr == null); + }); + } else { + resolve(err == null); + } }); }); }