From 67d22bd917c6ce38f9353e4d77d3a69079e1f096 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 13 Jun 2022 23:44:17 +0900 Subject: [PATCH] chore: add message for wildcard hosts --- packages/vite/src/node/constants.ts | 12 ++++++++++++ packages/vite/src/node/logger.ts | 29 +++++++++++++++++++---------- packages/vite/src/node/utils.ts | 9 ++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 4e5d3da96f50da..3846d87c419616 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -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' +]) diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index c989449ebe1b48..d3ed4ce896d6fb 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -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' @@ -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, @@ -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.') + ) + } } diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index f962611a4ce200..9f8a2d0f508429 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -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 '.' @@ -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 {