From 57524662a5783c6dc6cacf1f10d0d8128687954a Mon Sep 17 00:00:00 2001 From: Ryan Nixon Date: Sat, 12 Feb 2022 10:16:27 -0800 Subject: [PATCH 1/2] Support websocket upgrades --- lib/http-server.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/http-server.js b/lib/http-server.js index dfe4c474..e4b61603 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -181,6 +181,12 @@ function HttpServer(options) { if (options.timeout !== undefined) { this.server.setTimeout(options.timeout); } + + if (typeof options.proxy === 'string') { + this.server.on('upgrade', function (request, socket, head) { + proxy.ws(request, socket, head); + }); + } } HttpServer.prototype.listen = function () { From 6e546cfea6da21f042c13ca5fc859ca6075f6422 Mon Sep 17 00:00:00 2001 From: Ryan Nixon Date: Sat, 12 Feb 2022 13:24:36 -0800 Subject: [PATCH 2/2] Adding options parameter --- lib/http-server.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/http-server.js b/lib/http-server.js index e4b61603..d732743e 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -181,10 +181,13 @@ function HttpServer(options) { if (options.timeout !== undefined) { this.server.setTimeout(options.timeout); } - + if (typeof options.proxy === 'string') { this.server.on('upgrade', function (request, socket, head) { - proxy.ws(request, socket, head); + proxy.ws(request, socket, head, { + target: options.proxy, + changeOrigin: true + }); }); } }