Commit ac63130a authored by Joe Haddad's avatar Joe Haddad Committed by Dan Abramov
Browse files

Show network address on start (#2155)

* Show network address on start

* Tweak visual representation
parent 4dc7c865
3 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file
Showing with 34 additions and 20 deletions
+34 -20
...@@ -17,7 +17,7 @@ const paths = require('./paths'); ...@@ -17,7 +17,7 @@ const paths = require('./paths');
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const host = process.env.HOST || '0.0.0.0'; const host = process.env.HOST || '0.0.0.0';
module.exports = function(proxy) { module.exports = function(proxy, allowedHost) {
return { return {
// Enable gzip compression of generated files. // Enable gzip compression of generated files.
compress: true, compress: true,
...@@ -67,6 +67,7 @@ module.exports = function(proxy) { ...@@ -67,6 +67,7 @@ module.exports = function(proxy) {
// See https://github.com/facebookincubator/create-react-app/issues/387. // See https://github.com/facebookincubator/create-react-app/issues/387.
disableDotRule: true, disableDotRule: true,
}, },
public: allowedHost,
proxy, proxy,
setup(app) { setup(app) {
// This lets us open files from the crash overlay. // This lets us open files from the crash overlay.
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
"react-scripts": "./bin/react-scripts.js" "react-scripts": "./bin/react-scripts.js"
}, },
"dependencies": { "dependencies": {
"@timer/detect-port": "1.1.2",
"address": "1.0.1",
"autoprefixer": "6.7.7", "autoprefixer": "6.7.7",
"babel-core": "6.23.1", "babel-core": "6.23.1",
"babel-eslint": "7.1.1", "babel-eslint": "7.1.1",
...@@ -33,7 +35,6 @@ ...@@ -33,7 +35,6 @@
"connect-history-api-fallback": "1.3.0", "connect-history-api-fallback": "1.3.0",
"cross-spawn": "4.0.2", "cross-spawn": "4.0.2",
"css-loader": "0.28.0", "css-loader": "0.28.0",
"@timer/detect-port": "1.1.2",
"dotenv": "2.0.0", "dotenv": "2.0.0",
"eslint": "3.16.1", "eslint": "3.16.1",
"eslint-config-react-app": "^0.6.1", "eslint-config-react-app": "^0.6.1",
......
...@@ -22,6 +22,7 @@ process.env.NODE_ENV = 'development'; ...@@ -22,6 +22,7 @@ process.env.NODE_ENV = 'development';
// Ensure environment variables are read. // Ensure environment variables are read.
require('../config/env'); require('../config/env');
const address = require('address');
const fs = require('fs'); const fs = require('fs');
const chalk = require('chalk'); const chalk = require('chalk');
const detect = require('@timer/detect-port'); const detect = require('@timer/detect-port');
...@@ -53,25 +54,23 @@ const HOST = process.env.HOST || '0.0.0.0'; ...@@ -53,25 +54,23 @@ const HOST = process.env.HOST || '0.0.0.0';
function run(port) { function run(port) {
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const formattedUrl = url.format({
protocol,
hostname: HOST,
port,
pathname: '/',
});
let prettyHost; const formatUrl = hostname =>
if (HOST === '0.0.0.0' || HOST === '::') { url.format({ protocol, hostname, port, pathname: '/' });
const isUnspecifiedAddress = HOST === '0.0.0.0' || HOST === '::';
let prettyHost, lanAddress;
if (isUnspecifiedAddress) {
prettyHost = 'localhost'; prettyHost = 'localhost';
try {
lanAddress = address.ip();
} catch (_e) {
// ignored
}
} else { } else {
prettyHost = HOST; prettyHost = HOST;
} }
const prettyUrl = url.format({ const prettyUrl = formatUrl(prettyHost);
protocol,
hostname: prettyHost,
port,
pathname: '/',
});
// Create a webpack compiler that is configured with custom messages. // Create a webpack compiler that is configured with custom messages.
const compiler = createWebpackCompiler( const compiler = createWebpackCompiler(
...@@ -81,9 +80,22 @@ function run(port) { ...@@ -81,9 +80,22 @@ function run(port) {
return; return;
} }
console.log(); console.log();
console.log('The app is running at:'); console.log(
`You can now view ${chalk.bold(require(paths.appPackageJson).name)} in the browser.`
);
console.log(); console.log();
console.log(` ${chalk.cyan(formattedUrl)}`);
if (isUnspecifiedAddress && lanAddress) {
console.log(
` ${chalk.bold('Local:')} ${chalk.cyan(prettyUrl)}`
);
console.log(
` ${chalk.bold('On Your Network:')} ${chalk.cyan(formatUrl(lanAddress))}`
);
} else {
console.log(` ${chalk.cyan(prettyUrl)}`);
}
console.log(); console.log();
console.log('Note that the development build is not optimized.'); console.log('Note that the development build is not optimized.');
console.log( console.log(
...@@ -98,7 +110,7 @@ function run(port) { ...@@ -98,7 +110,7 @@ function run(port) {
// Serve webpack assets generated by the compiler over a web sever. // Serve webpack assets generated by the compiler over a web sever.
const devServer = new WebpackDevServer( const devServer = new WebpackDevServer(
compiler, compiler,
devServerConfig(prepareProxy(proxy)) devServerConfig(prepareProxy(proxy), lanAddress)
); );
// Launch WebpackDevServer. // Launch WebpackDevServer.
...@@ -113,7 +125,7 @@ function run(port) { ...@@ -113,7 +125,7 @@ function run(port) {
console.log(chalk.cyan('Starting the development server...')); console.log(chalk.cyan('Starting the development server...'));
console.log(); console.log();
openBrowser(prettyUrl); openBrowser(formatUrl(prettyHost));
}); });
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment