Skip to content

Commit d2f27cf

Browse files
Niels GiesenKernelDeimos
authored andcommitted
Proxy websockets only with --websocket
1 parent 78972bf commit d2f27cf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bin/http-server

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if (argv.h || argv.help) {
5959
'',
6060
' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com',
6161
' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false',
62+
' --websocket Enable websocket proxy',
6263
'',
6364
' --username Username for basic authentication [none]',
6465
' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME',
@@ -84,6 +85,7 @@ var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
8485
sslPassphrase = process.env.NODE_HTTP_SERVER_SSL_PASSPHRASE,
8586
proxy = argv.P || argv.proxy,
8687
proxyOptions = argv['proxy-options'],
88+
websocket = argv.websocket,
8789
utc = argv.U || argv.utc,
8890
version = argv.v || argv.version,
8991
baseDir = argv['base-dir'],
@@ -181,6 +183,14 @@ function listen(port) {
181183
}
182184
}
183185

186+
if (websocket) {
187+
if (!proxy) {
188+
logger.warning(colors.yellow('WebSocket proxy will not be enabled because proxy is not enabled'));
189+
} else {
190+
options.websocket = true;
191+
}
192+
}
193+
184194
if (argv.cors) {
185195
options.cors = true;
186196
if (typeof argv.cors === 'string') {

lib/http-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function HttpServer(options) {
194194
// if passphrase is set, shim must be used as union does not support
195195
? require('./shims/https-server-shim')(serverOptions)
196196
: union.createServer(serverOptions);
197-
if (proxy) {
197+
if (proxy && options.websocket) {
198198
this.server.on('upgrade', function (request, socket, head) {
199199
proxy.ws(request, socket, head);
200200
});

0 commit comments

Comments
 (0)