From 4bfc45a7c559f88d3a1c0cbe5392fcaba0d3bb3a Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sun, 14 May 2017 21:21:18 -0400 Subject: [PATCH] Add support for IPv6 hosts --- packages/react-dev-utils/prepareProxy.js | 4 +++- packages/react-scripts/scripts/start.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/react-dev-utils/prepareProxy.js b/packages/react-dev-utils/prepareProxy.js index ea0e9f163b0..2e12e05bd29 100644 --- a/packages/react-dev-utils/prepareProxy.js +++ b/packages/react-dev-utils/prepareProxy.js @@ -73,7 +73,9 @@ module.exports = function prepareProxy(proxy) { // `proxy` lets you specify alternate servers for specific requests. // It can either be a string or an object conforming to the Webpack dev server proxy configuration // https://webpack.github.io/docs/webpack-dev-server.html - if (!proxy) return undefined; + if (!proxy) { + return undefined; + } if (typeof proxy !== 'object' && typeof proxy !== 'string') { console.log( chalk.red( diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index 69bdc4b7450..fc226c169c5 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -36,6 +36,7 @@ const config = require('../config/webpack.config.dev'); const devServerConfig = require('../config/webpackDevServer.config'); const createWebpackCompiler = require('./utils/createWebpackCompiler'); const prepareProxy = require('react-dev-utils/prepareProxy'); +const url = require('url'); const useYarn = fs.existsSync(paths.yarnLockFile); const cli = useYarn ? 'yarn' : 'npm'; @@ -52,6 +53,12 @@ const HOST = process.env.HOST || '0.0.0.0'; function run(port) { const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; + const formattedUrl = url.format({ + protocol, + hostname: HOST, + port, + pathname: '/', + }); // Create a webpack compiler that is configured with custom messages. const compiler = createWebpackCompiler( @@ -63,7 +70,7 @@ function run(port) { console.log(); console.log('The app is running at:'); console.log(); - console.log(` ${chalk.cyan(`${protocol}://${HOST}:${port}/`)}`); + console.log(` ${chalk.cyan(formattedUrl)}`); console.log(); console.log('Note that the development build is not optimized.'); console.log( @@ -93,7 +100,7 @@ function run(port) { console.log(chalk.cyan('Starting the development server...')); console.log(); - openBrowser(`${protocol}://${HOST}:${port}/`); + openBrowser(formattedUrl); }); }