diff --git a/docs/config/preview-options.md b/docs/config/preview-options.md index cf068bf74327ce..be4205ce525dcd 100644 --- a/docs/config/preview-options.md +++ b/docs/config/preview-options.md @@ -10,6 +10,13 @@ Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and pu This can be set via the CLI using `--host 0.0.0.0` or `--host`. +::: tip NOTE + +There are cases when other servers might respond instead of Vite. +See [`server.host`](./server-options#server-host) for more details. + +::: + ## preview.port - **Type:** `number` diff --git a/docs/config/server-options.md b/docs/config/server-options.md index aa187ae9b13b68..cb493c01421ceb 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -10,6 +10,30 @@ Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and pu This can be set via the CLI using `--host 0.0.0.0` or `--host`. +::: tip NOTE + +There are cases when other servers might respond instead of Vite. + +The first case is when `localhost` is used. Node.js below v17 reorders the result of DNS-resolved address by default. When accessing `localhost`, browsers use DNS to resolve the address and that address might differ from the address which Vite is listening. + +You could set [`dns.setDefaultResultOrder('verbatim')`](https://nodejs.org/docs/latest-v18.x/api/dns.html#dnssetdefaultresultorderorder) to disable the reordering behavior. Or you could set `server.host` to `127.0.0.1` explicitly. + +```js +// vite.config.js +import { defineConfig } from 'vite' +import dns from 'dns' + +dns.setDefaultResultOrder('verbatim') + +export default defineConfig({ + // omit +}) +``` + +The second case is when wildcard hosts (e.g. `0.0.0.0`) is used. This is because servers listening on non-wildcard hosts take priority over those listening on wildcard hosts. + +::: + ## server.port - **Type:** `number` diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index 1aec4c40643ed3..8133f7bb584bbc 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -8,7 +8,7 @@ import type { RollupError } from 'rollup' import type { CommonServerOptions } from './http' import type { Hostname } from './utils' import { resolveHostname } from './utils' -import { loopbackHosts, wildcardHosts } from './constants' +import { loopbackHosts } from './constants' import type { ResolvedConfig } from '.' export type LogType = 'error' | 'warn' | 'info' @@ -219,15 +219,6 @@ function printServerUrls( }) } - if (!hostname.host || wildcardHosts.has(hostname.host)) { - notes.push({ - label: 'Note', - message: colors.dim( - 'You are using a wildcard host. Ports might be overridden.' - ) - }) - } - const length = Math.max( ...[...urls, ...notes].map(({ label }) => label.length) )