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: Honor the host param when creating a websocket server #5617

Merged
merged 1 commit into from Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/ws.ts
Expand Up @@ -41,6 +41,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 @@ -59,11 +60,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