Skip to content

Commit

Permalink
Upgrade websocket proxies without initial http request
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesblight committed Mar 12, 2017
1 parent 35a44d1 commit f01de68
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f01de68

Please sign in to comment.