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

Function getLocalhostAddressIfDiffersFromDNS

packages/vite/src/node/utils.ts:924–942  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

922 * For example, when IPv6 is not supported on that machine/network.
923 */
924export function getLocalhostAddressIfDiffersFromDNS():
925 | Promise<string | undefined>
926 | undefined {
927 // dns.getDefaultResultOrder is not available in bun 1.3.11 and deno 2.7.11
928 // while this is a bug in bun and deno, since this function is commonly called,
929 // we give a workaround specially until the API is supported in a few versions
930 if (dns.getDefaultResultOrder && dns.getDefaultResultOrder() === 'verbatim') {
931 return undefined
932 }
933 return Promise.all([
934 dns.lookup('localhost'),
935 dns.lookup('localhost', { verbatim: true }),
936 ]).then(([nodeResult, dnsResult]) => {
937 const isSame =
938 nodeResult.family === dnsResult.family &&
939 nodeResult.address === dnsResult.address
940 return isSame ? undefined : nodeResult.address
941 })
942}
943
944export function diffDnsOrderChange(
945 oldUrls: ViteDevServer['resolvedUrls'],

Callers 2

utils.spec.tsFile · 0.90
resolveHostnameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected