Skip to content

Commit 9c53329

Browse files
committed
fix: HMR websocket connection with VITE_HOST=0.0.0.0
1 parent 4d24be0 commit 9c53329

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

vite.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const previewPort = Number(process.env.MUX_VITE_PREVIEW_PORT ?? "4173");
1717
// Allow localhost, 127.0.0.1, and all *.coder domains
1818
// When host is 0.0.0.0, allow all hosts for remote access
1919
const allowedHosts = devServerHost === "0.0.0.0"
20-
? "all"
20+
? ["localhost", "127.0.0.1", "mux.coder", ".coder"]
2121
: ["localhost", "127.0.0.1", ".coder"];
2222

2323
const alias: Record<string, string> = {
@@ -125,8 +125,10 @@ export default defineConfig(({ mode }) => ({
125125
},
126126
hmr: {
127127
// Configure HMR to use the correct host for remote access
128-
host: devServerHost,
129-
port: devServerPort,
128+
// When server binds to 0.0.0.0, clients should connect via their actual hostname
129+
// Use clientPort to ensure HMR connects through the right port
130+
host: devServerHost === "0.0.0.0" ? undefined : devServerHost,
131+
clientPort: devServerPort,
130132
protocol: "ws",
131133
},
132134
},

0 commit comments

Comments
 (0)