Skip to content

Commit

Permalink
refactor: extract a few variables
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 14, 2022
1 parent 8a73ecf commit d3c4eb5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/vite/src/node/server/ws.ts
Expand Up @@ -28,11 +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) ||
(config.server.port && hmr.port !== config.server.port)) &&
server)
const hmrServer = hmr && hmr.server
const hmrPort = hmr && hmr.port
const portsNotEqual = config.server.port && hmr.port !== config.server.port
const wsServer = hmrServer || (server && (!hmrPort || portsNotEqual))

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

0 comments on commit d3c4eb5

Please sign in to comment.