Skip to content

Commit

Permalink
Revert "chore: simplify"
Browse files Browse the repository at this point in the history
This reverts commit aa1fc80.
  • Loading branch information
benmccann committed Mar 22, 2022
1 parent aa1fc80 commit 053e01d
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 @@ -29,8 +29,9 @@ export function createWebSocketServer(

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

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

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

0 comments on commit 053e01d

Please sign in to comment.