diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index 62abbc028486aa..9c1e04353180c3 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -93,6 +93,11 @@ export async function preview( const logger = config.logger const app = connect() as Connect.Server + + const hostname = await resolveHostname(options.host) + const port = options.port ?? 4173 + const protocol = options.https ? 'https' : 'http' + const httpServer = await resolveHttpServer( config.preview, app, @@ -100,6 +105,13 @@ export async function preview( ) setClientErrorHandler(httpServer, config.logger) + const serverPort = await httpServerStart(httpServer, { + port, + strictPort: options.strictPort, + host: hostname.host, + logger, + }) + const resolvedUrls = await resolveServerUrls( httpServer, config.preview, @@ -162,17 +174,6 @@ export async function preview( // apply post server hooks from plugins postHooks.forEach((fn) => fn && fn()) - const hostname = await resolveHostname(options.host) - const port = options.port ?? 4173 - const protocol = options.https ? 'https' : 'http' - - const serverPort = await httpServerStart(httpServer, { - port, - strictPort: options.strictPort, - host: hostname.host, - logger, - }) - if (options.open) { const path = typeof options.open === 'string' ? options.open : previewBase openBrowser(