diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 1fac81455f53b..957cc708e6121 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -14,7 +14,7 @@ const handlerP = fn => (...args) => { } function buildLocalCommands(cli, isLocalSite) { - const defaultHost = `0.0.0.0` + const defaultHost = process.platform === `win32` ? `localhost` : `0.0.0.0` const directory = path.resolve(`.`) let siteInfo = { directory, browserslist: DEFAULT_BROWSERS } diff --git a/packages/gatsby/src/commands/develop.js b/packages/gatsby/src/commands/develop.js index 8dd1cf49aeb18..0212bc5bbb636 100644 --- a/packages/gatsby/src/commands/develop.js +++ b/packages/gatsby/src/commands/develop.js @@ -254,9 +254,8 @@ module.exports = async (program: any) => { }) const isUnspecifiedHost = host === `0.0.0.0` || host === `::` - let prettyHost, lanUrlForConfig, lanUrlForTerminal + let lanUrlForConfig, lanUrlForTerminal if (isUnspecifiedHost) { - prettyHost = `localhost` try { // This can only return an IPv4 address lanUrlForConfig = address.ip() @@ -278,14 +277,12 @@ module.exports = async (program: any) => { } catch (_e) { // ignored } - } else { - prettyHost = host } // TODO collect errors (GraphQL + Webpack) in Redux so we // can clear terminal and print them out on every compile. // Borrow pretty printing code from webpack plugin. - const localUrlForTerminal = prettyPrintUrl(prettyHost) - const localUrlForBrowser = formatUrl(prettyHost) + const localUrlForTerminal = prettyPrintUrl(host) + const localUrlForBrowser = formatUrl(host) return { lanUrlForConfig, lanUrlForTerminal, @@ -318,11 +315,6 @@ module.exports = async (program: any) => { console.log() } - const host = - listener.address().address === `127.0.0.1` - ? `localhost` - : listener.address().address - let isFirstCompile = true // "done" event fires when Webpack has finished recompiling the bundle. // Whether or not you have warnings or errors, you will get this event. @@ -331,7 +323,7 @@ module.exports = async (program: any) => { // options so we are going to "massage" the warnings and errors and present // them in a readable focused way. const messages = formatWebpackMessages(stats.toJson({}, true)) - const urls = prepareUrls(`http`, host, port) + const urls = prepareUrls(`http`, program.host, program.port) const isSuccessful = !messages.errors.length && !messages.warnings.length // if (isSuccessful) { // console.log(chalk.green(`Compiled successfully!`))