From f01de6872b2bf83f48de1eecb52b280907cc29a5 Mon Sep 17 00:00:00 2001 From: James Blight Date: Sun, 12 Mar 2017 17:43:11 +1030 Subject: [PATCH] Upgrade websocket proxies without initial http request --- lib/Server.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Server.js b/lib/Server.js index 3c2d3e8b78..4a952da567 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -127,6 +127,9 @@ function Server(compiler, options) { contentBase = process.cwd(); } + // Keep track of websocket proxies for external websocket upgrade. + const websocketProxies = []; + const features = { compress() { if(options.compress) { @@ -205,6 +208,9 @@ function Server(compiler, options) { } proxyMiddleware = getProxyMiddleware(proxyConfig); + if(proxyConfig.ws) { + websocketProxies.push(proxyMiddleware); + } app.use((req, res, next) => { if(typeof proxyConfigOrCallback === "function") { @@ -361,6 +367,12 @@ function Server(compiler, options) { } else { this.listeningApp = http.createServer(app); } + + // Proxy websockets without the initial http request + // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade + websocketProxies.forEach(function(wsProxy) { + this.listeningApp.on("upgrade", wsProxy.upgrade); + }); } Server.prototype.use = function() {