Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consider undefined port when checking port #7318

Merged
merged 9 commits into from Mar 23, 2022
9 changes: 5 additions & 4 deletions packages/vite/src/node/server/ws.ts
Expand Up @@ -28,9 +28,10 @@ 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
benmccann marked this conversation as resolved.
Show resolved Hide resolved
const portsAreCompatible = !hmrPort || hmrPort === config.server.port
const wsServer = hmrServer || (portsAreCompatible && server)

if (wsServer) {
wss = new WebSocket({ noServer: true })
Expand All @@ -43,7 +44,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