Skip to content

Commit

Permalink
fix: move server start before url resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
erxclau committed Jan 10, 2023
1 parent 1a802f7 commit aab2019
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/vite/src/node/preview.ts
Expand Up @@ -93,13 +93,25 @@ 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,
await resolveHttpsConfig(config.preview?.https),
)
setClientErrorHandler(httpServer, config.logger)

const serverPort = await httpServerStart(httpServer, {
port,
strictPort: options.strictPort,
host: hostname.host,
logger,
})

const resolvedUrls = await resolveServerUrls(
httpServer,
config.preview,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit aab2019

Please sign in to comment.