Skip to content

Commit 67d22bd

Browse files
committed
chore: add message for wildcard hosts
1 parent 7b88dff commit 67d22bd

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

packages/vite/src/node/constants.ts

+12
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,15 @@ export const DEFAULT_ASSETS_RE = new RegExp(
9999
)
100100

101101
export const DEP_VERSION_RE = /[\?&](v=[\w\.-]+)\b/
102+
103+
export const loopbackHosts = new Set([
104+
'localhost',
105+
'127.0.0.1',
106+
'::1',
107+
'0000:0000:0000:0000:0000:0000:0000:0001'
108+
])
109+
export const wildcardHosts = new Set([
110+
'0.0.0.0',
111+
'::',
112+
'0000:0000:0000:0000:0000:0000:0000:0000'
113+
])

packages/vite/src/node/logger.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { RollupError } from 'rollup'
88
import type { CommonServerOptions } from './http'
99
import type { Hostname } from './utils'
1010
import { resolveHostname } from './utils'
11+
import { loopbackHosts, wildcardHosts } from './constants'
1112
import type { ResolvedConfig } from '.'
1213

1314
export type LogType = 'error' | 'warn' | 'info'
@@ -164,13 +165,6 @@ export function printCommonServerUrls(
164165
}
165166
}
166167

167-
const loopbackHosts = new Set([
168-
'localhost',
169-
'127.0.0.1',
170-
'::1',
171-
'0000:0000:0000:0000:0000:0000:0000:0001'
172-
])
173-
174168
function printServerUrls(
175169
hostname: Hostname,
176170
protocol: string,
@@ -227,11 +221,26 @@ function printServerUrls(
227221
(length, { label }) => Math.max(length, label.length),
228222
0
229223
)
230-
urls.forEach(({ label, url: text }) => {
224+
const print = (
225+
iconWithColor: string,
226+
label: string,
227+
messageWithColor: string
228+
) => {
231229
info(
232-
` ${colors.green('➜')} ${colors.bold(label)}: ${' '.repeat(
230+
` ${iconWithColor} ${colors.bold(label)}: ${' '.repeat(
233231
length - label.length
234-
)}${text}`
232+
)}${messageWithColor}`
235233
)
234+
}
235+
236+
urls.forEach(({ label, url: text }) => {
237+
print(colors.green('➜'), label, text)
236238
})
239+
if (!hostname.host || wildcardHosts.has(hostname.host)) {
240+
print(
241+
colors.bold(colors.blue('ⓘ')),
242+
'Note',
243+
colors.dim('You are using a wildcard host. Ports might be overriden.')
244+
)
245+
}
237246
}

packages/vite/src/node/utils.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
DEFAULT_EXTENSIONS,
2323
ENV_PUBLIC_PATH,
2424
FS_PREFIX,
25-
VALID_ID_PREFIX
25+
VALID_ID_PREFIX,
26+
wildcardHosts
2627
} from './constants'
2728
import type { ResolvedConfig } from '.'
2829

@@ -726,12 +727,6 @@ export interface Hostname {
726727
name: string
727728
}
728729

729-
const wildcardHosts = new Set([
730-
'0.0.0.0',
731-
'::',
732-
'0000:0000:0000:0000:0000:0000:0000:0000'
733-
])
734-
735730
export function resolveHostname(
736731
optionsHost: string | boolean | undefined
737732
): Hostname {

0 commit comments

Comments
 (0)