Skip to content

Commit 3ee04c0

Browse files
authored
fix: use hmr port if specified (#7282)
1 parent fae120a commit 3ee04c0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

docs/config/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export default defineConfig(({ command, mode }) => {
549549

550550
`clientPort` is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on. Useful if you're using an SSL proxy in front of your dev server.
551551

552-
When using `server.middlewareMode` or `server.https`, assigning `server.hmr.server` to your HTTP(S) server will process HMR connection requests through your server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
552+
If specifying `server.hmr.server`, Vite will process HMR connection requests through the provided server. If not in middleware mode, Vite will attempt to process HMR connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
553553

554554
### server.watch
555555

packages/vite/src/node/server/ws.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function createWebSocketServer(
2828
let httpsServer: Server | undefined = undefined
2929

3030
const hmr = isObject(config.server.hmr) && config.server.hmr
31-
const wsServer = (hmr && hmr.server) || server
31+
const wsServer =
32+
(hmr && hmr.server) ||
33+
((!(hmr && hmr.port) || hmr.port !== config.server.port) && server)
3234

3335
if (wsServer) {
3436
wss = new WebSocket({ noServer: true })

0 commit comments

Comments
 (0)