Skip to content

Commit f01de68

Browse files
committed
Upgrade websocket proxies without initial http request
1 parent 35a44d1 commit f01de68

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/Server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ function Server(compiler, options) {
127127
contentBase = process.cwd();
128128
}
129129

130+
// Keep track of websocket proxies for external websocket upgrade.
131+
const websocketProxies = [];
132+
130133
const features = {
131134
compress() {
132135
if(options.compress) {
@@ -205,6 +208,9 @@ function Server(compiler, options) {
205208
}
206209

207210
proxyMiddleware = getProxyMiddleware(proxyConfig);
211+
if(proxyConfig.ws) {
212+
websocketProxies.push(proxyMiddleware);
213+
}
208214

209215
app.use((req, res, next) => {
210216
if(typeof proxyConfigOrCallback === "function") {
@@ -361,6 +367,12 @@ function Server(compiler, options) {
361367
} else {
362368
this.listeningApp = http.createServer(app);
363369
}
370+
371+
// Proxy websockets without the initial http request
372+
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
373+
websocketProxies.forEach(function(wsProxy) {
374+
this.listeningApp.on("upgrade", wsProxy.upgrade);
375+
});
364376
}
365377

366378
Server.prototype.use = function() {

0 commit comments

Comments
 (0)