Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 22, 2022
1 parent 975d9cd commit aa1fc80
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/vite/src/node/server/ws.ts
Expand Up @@ -29,9 +29,8 @@ export function createWebSocketServer(

const hmr = isObject(config.server.hmr) && config.server.hmr
const hmrServer = hmr && hmr.server
const hmrPort = hmr && hmr.port
const portsNotEqual = config.server.port && hmrPort !== config.server.port
const wsServer = hmrServer || ((!hmrPort || portsNotEqual) && server)
const hmrPort = (hmr && hmr.port) || 24678
const wsServer = hmrServer || (hmrPort !== config.server.port && server)

if (wsServer) {
wss = new WebSocket({ noServer: true })
Expand All @@ -44,7 +43,6 @@ export function createWebSocketServer(
})
} else {
const websocketServerOptions: ServerOptions = {}
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 All @@ -64,11 +62,11 @@ export function createWebSocketServer(
res.end(body)
})

httpsServer.listen(port, host)
httpsServer.listen(hmrPort, host)
websocketServerOptions.server = httpsServer
} else {
// we don't need to serve over https, just let ws handle its own server
websocketServerOptions.port = port
websocketServerOptions.port = hmrPort
if (host) {
websocketServerOptions.host = host
}
Expand Down

0 comments on commit aa1fc80

Please sign in to comment.