Skip to content

Commit

Permalink
fix: honor the host param when creating a websocket server (#5617)
Browse files Browse the repository at this point in the history
  • Loading branch information
casret committed Mar 3, 2022
1 parent e0a4d81 commit 882c8a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/ws.ts
Expand Up @@ -42,6 +42,7 @@ export function createWebSocketServer(
} else {
const websocketServerOptions: ServerOptions = {}
const port = (hmr && hmr.port) || 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
// create an inline https server and mount the websocket server to it
Expand All @@ -60,11 +61,14 @@ export function createWebSocketServer(
res.end(body)
})

httpsServer.listen(port)
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 = port
if (host) {
websocketServerOptions.host = host
}
}

// vite dev server in middleware mode
Expand Down

0 comments on commit 882c8a8

Please sign in to comment.