Skip to content

Commit

Permalink
fix: consider undefined port when checking port (#7318)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 23, 2022
1 parent 74277ec commit c7fc7c3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vite/src/node/server/ws.ts
Expand Up @@ -28,9 +28,11 @@ export function createWebSocketServer(
let httpsServer: Server | undefined = undefined

const hmr = isObject(config.server.hmr) && config.server.hmr
const wsServer =
(hmr && hmr.server) ||
((!(hmr && hmr.port) || hmr.port !== config.server.port) && server)
const hmrServer = hmr && hmr.server
const hmrPort = hmr && hmr.port
// TODO: the main server port may not have been chosen yet as it may use the next available
const portsAreCompatible = !hmrPort || hmrPort === config.server.port
const wsServer = hmrServer || (portsAreCompatible && server)

if (wsServer) {
wss = new WebSocket({ noServer: true })
Expand All @@ -43,7 +45,7 @@ export function createWebSocketServer(
})
} else {
const websocketServerOptions: ServerOptions = {}
const port = (hmr && hmr.port) || 24678
const port = hmrPort || 24678
const host = (hmr && hmr.host) || undefined
if (httpsOptions) {
// if we're serving the middlewares over https, the ws library doesn't support automatically creating an https server, so we need to do it ourselves
Expand Down

0 comments on commit c7fc7c3

Please sign in to comment.