MCPcopy
hub / github.com/vitejs/vite / resolveHostname

Function resolveHostname

packages/vite/src/node/utils.ts:964–990  ·  view source on GitHub ↗
(
  optionsHost: string | boolean | undefined,
)

Source from the content-addressed store, hash-verified

962}
963
964export async function resolveHostname(
965 optionsHost: string | boolean | undefined,
966): Promise<Hostname> {
967 let host: string | undefined
968 if (optionsHost === undefined || optionsHost === false) {
969 // Use a secure default
970 host = 'localhost'
971 } else if (optionsHost === true) {
972 // If passed --host in the CLI without arguments
973 host = undefined // undefined typically means 0.0.0.0 or :: (listen on all IPs)
974 } else {
975 host = optionsHost
976 }
977
978 // Set host name to localhost when possible
979 let name = host === undefined || wildcardHosts.has(host) ? 'localhost' : host
980
981 if (host === 'localhost') {
982 // See #8647 for more details.
983 const localhostAddr = await getLocalhostAddressIfDiffersFromDNS()
984 if (localhostAddr) {
985 name = localhostAddr
986 }
987 }
988
989 return { host, name }
990}
991
992export function extractHostnamesFromCerts(
993 certs: HttpsServerOptions['cert'] | undefined,

Callers 5

resolveDevToolsConfigFunction · 0.90
previewFunction · 0.90
listenFunction · 0.90
utils.spec.tsFile · 0.90

Calls 2

hasMethod · 0.80

Tested by

no test coverage detected