Skip to content

Commit 52e0f8f

Browse files
ajhyndmanbjohansebas
authored andcommitted
fix: never proxy hot-reload websocket requests
Both create-react-app and vue-cli-service have introduced workarounds for this, but it seems to me that this is always desirable behaviour for webpack-dev-server. vuejs/vue-cli@72ba750 react/create-react-app#7444
1 parent b550a70 commit 52e0f8f

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

lib/Server.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,13 +1850,31 @@ class Server {
18501850
/** @type {RequestHandler[]} */
18511851
(this.webSocketProxies);
18521852

1853+
const hmrPath =
1854+
this.options.webSocketServer &&
1855+
/** @type {WebSocketServerConfiguration} */
1856+
(this.options.webSocketServer).options &&
1857+
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
1858+
(
1859+
/** @type {WebSocketServerConfiguration} */
1860+
(this.options.webSocketServer).options
1861+
).path;
1862+
18531863
for (const webSocketProxy of webSocketProxies) {
1854-
/** @type {S} */
1855-
(this.server).on(
1856-
"upgrade",
1864+
const proxyUpgrade =
18571865
/** @type {RequestHandler & { upgrade: NonNullable<RequestHandler["upgrade"]> }} */
1858-
(webSocketProxy).upgrade,
1859-
);
1866+
(webSocketProxy).upgrade;
1867+
1868+
/** @type {S} */
1869+
(this.server).on("upgrade", (req, socket, head) => {
1870+
if (hmrPath && req.url) {
1871+
const { pathname } = new URL(req.url, "http://0.0.0.0");
1872+
if (pathname === hmrPath) {
1873+
return;
1874+
}
1875+
}
1876+
proxyUpgrade(req, socket, head);
1877+
});
18601878
}
18611879
}
18621880

0 commit comments

Comments
 (0)