Skip to content

Commit 78972bf

Browse files
Niels GiesenKernelDeimos
authored andcommitted
Proxy websocket requests
1 parent 9c20674 commit 78972bf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/http-server.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ function HttpServer(options) {
157157

158158
if (typeof options.proxy === 'string') {
159159
var proxyOptions = options.proxyOptions || {};
160-
var proxy = httpProxy.createProxyServer(proxyOptions);
160+
var proxy = httpProxy.createProxyServer({
161+
...proxyOptions,
162+
target: options.proxy,
163+
changeOrigin: true,
164+
});
161165
before.push(function (req, res) {
162-
proxy.web(req, res, {
163-
target: options.proxy,
164-
changeOrigin: true
165-
}, function (err, req, res) {
166+
proxy.web(req, res, {}, function (err, req, res) {
166167
if (options.logFn) {
167168
options.logFn(req, res, {
168169
message: err.message,
@@ -193,6 +194,11 @@ function HttpServer(options) {
193194
// if passphrase is set, shim must be used as union does not support
194195
? require('./shims/https-server-shim')(serverOptions)
195196
: union.createServer(serverOptions);
197+
if (proxy) {
198+
this.server.on('upgrade', function (request, socket, head) {
199+
proxy.ws(request, socket, head);
200+
});
201+
}
196202

197203
if (options.timeout !== undefined) {
198204
this.server.setTimeout(options.timeout);

0 commit comments

Comments
 (0)