From cdd619aa80af53b6971e12da5ee89d25be000a21 Mon Sep 17 00:00:00 2001 From: bluwy Date: Sat, 18 Jun 2022 00:10:50 +0800 Subject: [PATCH 1/2] fix(server): lookup localhost without explicit verbatim --- packages/vite/src/node/http.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index c2757f36477600..23f4856d0995eb 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -187,10 +187,8 @@ export async function httpServerStart( ): Promise { let { port, strictPort, host, logger } = serverOptions - // This could be removed when Vite only supports Node 17+ because verbatim=true is default - // https://github.com/nodejs/node/pull/39987 if (host === 'localhost') { - const addr = await dns.lookup('localhost', { verbatim: true }) + const addr = await dns.lookup('localhost') host = addr.address } From f3d1acaf35c7974378e7102f12f14c2b4e53fe39 Mon Sep 17 00:00:00 2001 From: bluwy Date: Sat, 18 Jun 2022 00:27:23 +0800 Subject: [PATCH 2/2] refactor: remove dns lookup --- packages/vite/src/node/http.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 23f4856d0995eb..8710c274fd83d1 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -5,7 +5,6 @@ import type { OutgoingHttpHeaders as HttpServerHeaders } from 'http' import type { ServerOptions as HttpsServerOptions } from 'https' -import { promises as dns } from 'dns' import type { Connect } from 'types/connect' import { isObject } from './utils' import type { ProxyOptions } from './server/middlewares/proxy' @@ -187,11 +186,6 @@ export async function httpServerStart( ): Promise { let { port, strictPort, host, logger } = serverOptions - if (host === 'localhost') { - const addr = await dns.lookup('localhost') - host = addr.address - } - return new Promise((resolve, reject) => { const onError = (e: Error & { code?: string }) => { if (e.code === 'EADDRINUSE') {