Skip to content

Commit 3380a29

Browse files
patak-cataleclarson
authored andcommitted
fix: config port timing, fix vitejs#4094 (vitejs#4104)
1 parent e96b2ac commit 3380a29

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/vite/src/node/server/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ export async function createServer(
435435
handleFileAddUnlink(normalizePath(file), server, true)
436436
})
437437

438+
if (!middlewareMode && httpServer) {
439+
httpServer.once('listening', () => {
440+
// update actual port since this may be different from initial value
441+
serverConfig.port = (httpServer.address() as AddressInfo).port
442+
})
443+
}
444+
438445
// apply server configuration hooks from plugins
439446
const postHooks: ((() => void) | void)[] = []
440447
for (const plugin of plugins) {
@@ -564,11 +571,6 @@ export async function createServer(
564571
}
565572
return listen(port, ...args)
566573
}) as any
567-
568-
httpServer.once('listening', () => {
569-
// update actual port since this may be different from initial value
570-
serverConfig.port = (httpServer.address() as AddressInfo).port
571-
})
572574
} else {
573575
await container.buildStart({})
574576
await runOptimize()

0 commit comments

Comments
 (0)