Skip to content

Commit df5c8ef

Browse files
author
Shane Osbourne
committed
Put web socket support via proxy behind an option wall, proxy.ws.
Websocket proxying is not the common use-case and introducing an extra port requirement would be a breaking change for some users.
1 parent 29dfd0a commit df5c8ef

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

lib/async.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ module.exports = {
4242
return done();
4343
}
4444

45+
/**
46+
* Web socket support is disabled by default
47+
*/
48+
if (!bs.options.getIn(["proxy", "ws"])) {
49+
return done();
50+
}
51+
4552
/**
4653
* Use 1 higher than server port by default...
4754
*/

lib/browser-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ BrowserSync.prototype.getExternalSocketConnector = function (opts) {
468468
return connectUtils.socketConnector(
469469
bs.options.withMutations(function (item) {
470470
item.set("socket", item.get("socket").merge(opts));
471-
if (bs.options.get("mode") !== "proxy") {
471+
if (!bs.options.getIn(["proxy", "ws"])) {
472472
item.set("mode", "snippet");
473473
}
474474
})

lib/connect-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var connectUtils = {
101101
string = withHostnamePort;
102102
}
103103

104-
if (options.get("mode") === "proxy") {
104+
if (options.get("mode") === "proxy" && options.getIn(["proxy", "ws"])) {
105105
port = options.getIn(["socket", "port"]);
106106
}
107107

lib/sockets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports.init = function (server, clientEvents, bs) {
2525
.get("socket")
2626
.toJS();
2727

28-
if (bs.options.get("mode") === "proxy") {
28+
if (bs.options.get("mode") === "proxy" && bs.options.getIn(["proxy", "ws"])) {
2929
server = utils.getServer(null, bs.options).server;
3030
server.listen(bs.options.getIn(["socket", "port"]));
3131
bs.registerCleanupTask(function () {

test/specs/e2e/e2e.options.port.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ describe("E2E `port` option", function () {
3737

3838
var config = {
3939
logLevel: "silent",
40-
proxy: "localhost",
40+
proxy: {
41+
target: "localhost",
42+
ws: true
43+
},
4144
online: false,
4245
open: false
4346
};
@@ -61,7 +64,10 @@ describe("E2E `port` option", function () {
6164

6265
var config = {
6366
logLevel: "silent",
64-
proxy: "localhost",
67+
proxy: {
68+
target: "localhost",
69+
ws: true
70+
},
6571
socket: {
6672
port: 8001
6773
},

test/specs/utils/utils.connect.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe("Connection utils", function () {
3737
port: 3002,
3838
scheme: "http",
3939
mode: "proxy",
40+
proxy: {
41+
target: "localhost",
42+
ws: true
43+
},
4044
socket: {
4145
port: 4000
4246
}

0 commit comments

Comments
 (0)