From 67990900cd7650589eb86f94d0bd219849ffc0ba Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 19 Jul 2021 15:44:09 -0500 Subject: [PATCH 1/3] Fix default server host value --- packages/next/cli/next-dev.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/next/cli/next-dev.ts b/packages/next/cli/next-dev.ts index 4619b0a0e7b4..0eabec7e52b6 100755 --- a/packages/next/cli/next-dev.ts +++ b/packages/next/cli/next-dev.ts @@ -73,12 +73,16 @@ const nextDev: cliCommand = (argv) => { const port = args['--port'] || (process.env.PORT && parseInt(process.env.PORT)) || 3000 - const host = args['--hostname'] || '0.0.0.0' - const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}` + + // We do not set a default host value here to prevent breaking + // some set-ups that rely on listening on other interfaces + const host = args['--hostname'] + const ipPort = `${!host ? 'localhost' : host}:${port}` + const appUrl = `http://${ipPort}` startServer({ dir, dev: true, isNextDevCommand: true }, port, host) .then(async (app) => { - startedDevelopmentServer(appUrl, `${host}:${port}`) + startedDevelopmentServer(appUrl, ipPort) // Start preflight after server is listening and ignore errors: preflight().catch(() => {}) // Finalize server bootup: From 70de745e15b5152472729222f884d7848b56601d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 19 Jul 2021 16:17:44 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Steven --- packages/next/cli/next-dev.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/cli/next-dev.ts b/packages/next/cli/next-dev.ts index 0eabec7e52b6..75b3e975ae17 100755 --- a/packages/next/cli/next-dev.ts +++ b/packages/next/cli/next-dev.ts @@ -77,7 +77,7 @@ const nextDev: cliCommand = (argv) => { // We do not set a default host value here to prevent breaking // some set-ups that rely on listening on other interfaces const host = args['--hostname'] - const ipPort = `${!host ? 'localhost' : host}:${port}` + const ipPort = `${host || 'localhost'}:${port}` const appUrl = `http://${ipPort}` startServer({ dir, dev: true, isNextDevCommand: true }, port, host) From 9bd9e1b7dd155d3d2be0e28fac54c86d4a88c429 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 19 Jul 2021 16:44:44 -0500 Subject: [PATCH 3/3] Ensure output matches tests --- packages/next/cli/next-dev.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/next/cli/next-dev.ts b/packages/next/cli/next-dev.ts index 75b3e975ae17..e8f432daba41 100755 --- a/packages/next/cli/next-dev.ts +++ b/packages/next/cli/next-dev.ts @@ -77,12 +77,13 @@ const nextDev: cliCommand = (argv) => { // We do not set a default host value here to prevent breaking // some set-ups that rely on listening on other interfaces const host = args['--hostname'] - const ipPort = `${host || 'localhost'}:${port}` - const appUrl = `http://${ipPort}` + const appUrl = `http://${ + !host || host === '0.0.0.0' ? 'localhost' : host + }:${port}` startServer({ dir, dev: true, isNextDevCommand: true }, port, host) .then(async (app) => { - startedDevelopmentServer(appUrl, ipPort) + startedDevelopmentServer(appUrl, `${host || '0.0.0.0'}:${port}`) // Start preflight after server is listening and ignore errors: preflight().catch(() => {}) // Finalize server bootup: