Skip to content

Commit

Permalink
Fix default server host value causing issues on Windows (#27306)
Browse files Browse the repository at this point in the history
This fixes a case where the HMR connection for fast refresh would fail to connect on Windows due to a change being made to the default host being listened to. Previously we didn't set a default for the `host` value when calling `server.listen` which allowed the default listening behavior to be used although in #20409 a default of `0.0.0.0` was added which causes conflicts for some set-ups mainlly on Windows it seems. 

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added (N/A)
- [x] Errors have helpful link attached, see `contributing.md`

Fixes: #27298
Fixes: #27254
Fixes: #4456 (comment)
Fixes: #20409 (comment)
x-ref: #20409
  • Loading branch information
ijjk authored Jul 19, 2021
1 parent b123942 commit 1effbae
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/next/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ 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 appUrl = `http://${
!host || host === '0.0.0.0' ? 'localhost' : host
}:${port}`

startServer({ dir, dev: true, isNextDevCommand: true }, port, host)
.then(async (app) => {
startedDevelopmentServer(appUrl, `${host}:${port}`)
startedDevelopmentServer(appUrl, `${host || '0.0.0.0'}:${port}`)
// Start preflight after server is listening and ignore errors:
preflight().catch(() => {})
// Finalize server bootup:
Expand Down

0 comments on commit 1effbae

Please sign in to comment.