fix(dev): keep the page's Host on the Vite WebSocket proxy

b1108a9e made the panel reject a WebSocket upgrade whose Origin port
differs from the Host port. The dev proxy forwarded /ws with
changeOrigin, which rewrites Host to localhost:2053 while the browser
still sends Origin http://localhost:5173, so every upgrade was refused
with "request origin not allowed by Upgrader.CheckOrigin". Vite then
relayed that response to a socket the browser had already closed and
logged "ws proxy error: write EPIPE" on each reconnect, and live
updates never reached the dev server.

The /ws proxy now leaves Host alone, as a production reverse proxy
does. The HTTP proxies keep changeOrigin; they are not origin-checked.
This commit is contained in:
Sanaei
2026-12-03 19:22:47 +03:30
parent a49720e88a
commit eae4ff8e8f
+2 -1
View File
@@ -289,10 +289,11 @@ export default defineConfig({
'^/(?:[^/]+/)?(login|logout|getTwoFactorEnable|csrf-token|sponsors|panel|server)(?:/|$)': makeBackendProxy(BACKEND_TARGET),
'^/$': makeBackendProxy(BACKEND_TARGET),
'^/[^/]+/$': makeBackendProxy(BACKEND_TARGET),
// No changeOrigin: the panel rejects an upgrade whose Origin port differs
// from the Host port, so Host must stay the dev server the page came from.
'^/(?:[^/]+/)?ws$': {
target: 'ws://localhost:2053',
ws: true,
changeOrigin: true,
rewrite: rewriteToBackend,
},
},