Skip to content

Commit

Permalink
feat: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 13, 2021
1 parent c9b3d68 commit 0d26b87
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/vite/src/node/server/http.ts
Expand Up @@ -174,12 +174,14 @@ export async function httpServerStart(
let { port, strict, host, logger } = serverOptions

const onError = (e: Error & { code?: string }) => {
if (strict) {
httpServer.removeListener('error', onError)
reject(new Error(`Port ${port} is already in use`))
} else if (e.code === 'EADDRINUSE') {
logger.info(`Port ${port} is in use, trying another one...`)
httpServer.listen(++port, host)
if (e.code === 'EADDRINUSE') {
if (strict) {
httpServer.removeListener('error', onError)
reject(new Error(`Port ${port} is already in use`))
} else {
logger.info(`Port ${port} is in use, trying another one...`)
httpServer.listen(++port, host)
}
} else {
httpServer.removeListener('error', onError)
reject(e)
Expand Down

0 comments on commit 0d26b87

Please sign in to comment.