Skip to content

Commit

Permalink
fix: use hmr port if specified (#7282)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 14, 2022
1 parent fae120a commit 3ee04c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/config/index.md
Expand Up @@ -549,7 +549,7 @@ export default defineConfig(({ command, mode }) => {

`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.

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.
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.

### server.watch

Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/server/ws.ts
Expand Up @@ -28,7 +28,9 @@ export function createWebSocketServer(
let httpsServer: Server | undefined = undefined

const hmr = isObject(config.server.hmr) && config.server.hmr
const wsServer = (hmr && hmr.server) || server
const wsServer =
(hmr && hmr.server) ||
((!(hmr && hmr.port) || hmr.port !== config.server.port) && server)

if (wsServer) {
wss = new WebSocket({ noServer: true })
Expand Down

0 comments on commit 3ee04c0

Please sign in to comment.