Skip to content

Commit

Permalink
fix: config port timing, fix #4094 (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jul 30, 2021
1 parent bd7c148 commit 6b98fdd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ export async function createServer(
handleFileAddUnlink(normalizePath(file), server, true)
})

if (!middlewareMode && httpServer) {
httpServer.once('listening', () => {
// update actual port since this may be different from initial value
serverConfig.port = (httpServer.address() as AddressInfo).port
})
}

// apply server configuration hooks from plugins
const postHooks: ((() => void) | void)[] = []
for (const plugin of plugins) {
Expand Down Expand Up @@ -564,11 +571,6 @@ export async function createServer(
}
return listen(port, ...args)
}) as any

httpServer.once('listening', () => {
// update actual port since this may be different from initial value
serverConfig.port = (httpServer.address() as AddressInfo).port
})
} else {
await container.buildStart({})
await runOptimize()
Expand Down

0 comments on commit 6b98fdd

Please sign in to comment.