Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Fix default server host value causing issues on Windows (vercel#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 vercel#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: vercel#27298
Fixes: vercel#27254
Fixes: vercel#4456 (comment)
Fixes: vercel#20409 (comment)
x-ref: vercel#20409
  • Loading branch information
ijjk committed Jul 19, 2021
1 parent 7909aad commit 896ce0c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/next/cli/next-dev.ts
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 896ce0c

Please sign in to comment.