diff --git a/lib/configproxy.js b/lib/configproxy.js index 7967527f..4f192738 100644 --- a/lib/configproxy.js +++ b/lib/configproxy.js @@ -176,6 +176,24 @@ export class ConfigurableProxy extends EventEmitter { } options.ws = true; this.proxy = httpProxy.createProxyServer(options); + this.proxy.on("proxyReqWs", (proxyReq, req, socket, options, head) => { + proxyReq.on("response", (res) => { + that.log.info( + "Client requested websocket at %s, proxy target %s responded with HTTP %s %s", + req.url, + proxyReq.host, + res.statusCode, + res.statusMessage + ); + if (!socket.destroyed) { + socket.write( + `HTTP/1.1 ${res.statusCode} Upstream not a websocket\r\nConnection: close\r\n\r\n` + ); + socket.end(); + } + res.resume(); + }); + }); // tornado-style regex routing, // because cross-language cargo-culting is always a good idea