Skip to content

Commit

Permalink
chore: add message for wildcard hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jun 13, 2022
1 parent 7b88dff commit 67d22bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
12 changes: 12 additions & 0 deletions packages/vite/src/node/constants.ts
Expand Up @@ -99,3 +99,15 @@ export const DEFAULT_ASSETS_RE = new RegExp(
)

export const DEP_VERSION_RE = /[\?&](v=[\w\.-]+)\b/

export const loopbackHosts = new Set([
'localhost',
'127.0.0.1',
'::1',
'0000:0000:0000:0000:0000:0000:0000:0001'
])
export const wildcardHosts = new Set([
'0.0.0.0',
'::',
'0000:0000:0000:0000:0000:0000:0000:0000'
])
29 changes: 19 additions & 10 deletions packages/vite/src/node/logger.ts
Expand Up @@ -8,6 +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 type { ResolvedConfig } from '.'

export type LogType = 'error' | 'warn' | 'info'
Expand Down Expand Up @@ -164,13 +165,6 @@ export function printCommonServerUrls(
}
}

const loopbackHosts = new Set([
'localhost',
'127.0.0.1',
'::1',
'0000:0000:0000:0000:0000:0000:0000:0001'
])

function printServerUrls(
hostname: Hostname,
protocol: string,
Expand Down Expand Up @@ -227,11 +221,26 @@ function printServerUrls(
(length, { label }) => Math.max(length, label.length),
0
)
urls.forEach(({ label, url: text }) => {
const print = (
iconWithColor: string,
label: string,
messageWithColor: string
) => {
info(
` ${colors.green('➜')} ${colors.bold(label)}: ${' '.repeat(
` ${iconWithColor} ${colors.bold(label)}: ${' '.repeat(
length - label.length
)}${text}`
)}${messageWithColor}`
)
}

urls.forEach(({ label, url: text }) => {
print(colors.green('➜'), label, text)
})
if (!hostname.host || wildcardHosts.has(hostname.host)) {
print(
colors.bold(colors.blue('ⓘ')),
'Note',
colors.dim('You are using a wildcard host. Ports might be overriden.')
)
}
}
9 changes: 2 additions & 7 deletions packages/vite/src/node/utils.ts
Expand Up @@ -22,7 +22,8 @@ import {
DEFAULT_EXTENSIONS,
ENV_PUBLIC_PATH,
FS_PREFIX,
VALID_ID_PREFIX
VALID_ID_PREFIX,
wildcardHosts
} from './constants'
import type { ResolvedConfig } from '.'

Expand Down Expand Up @@ -726,12 +727,6 @@ export interface Hostname {
name: string
}

const wildcardHosts = new Set([
'0.0.0.0',
'::',
'0000:0000:0000:0000:0000:0000:0000:0000'
])

export function resolveHostname(
optionsHost: string | boolean | undefined
): Hostname {
Expand Down

0 comments on commit 67d22bd

Please sign in to comment.