Skip to content

Commit 7735b1b

Browse files
committed
use https url for socket when page is loaded over htpps
1 parent 5577643 commit 7735b1b

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/templates/connector.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ ___browserSync___.io = window.io;
33
window.io = window.___browserSync___oldSocketIo;
44
window.___browserSync___oldSocketIo=undefined;
55
___browserSync___.socketConfig = %config%;
6-
___browserSync___.socket = ___browserSync___.io(%url%, ___browserSync___.socketConfig);
6+
___browserSync___.url = %url%;
7+
if (location.protocol == "https:" && /^http:/.test(___browserSync___.url)) {
8+
___browserSync___.url = ___browserSync___.url.replace(/^http:/, "https:");
9+
}
10+
___browserSync___.socket = ___browserSync___.io(___browserSync___.url, ___browserSync___.socketConfig);

test/specs/e2e/e2e.options.scriptpath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("E2E Socket path test - given a callback", function () {
6060
.get(instance.options.getIn(["scriptPaths", "path"]))
6161
.expect(200)
6262
.end(function (err, res) {
63-
assert.include(res.text, "io('' + location.host + '/TEST',");
63+
assert.include(res.text, "___browserSync___.url = '' + location.host + '/TEST';");
6464
done();
6565
});
6666
});

test/specs/utils/utils.connect.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("Connection utils", function () {
9494
}
9595
});
9696
var actual = utils.socketConnector(options);
97-
assert.include(actual, "___browserSync___.io('localhost:3000/browser-sync', ___browserSync___.socketConfig);");
97+
assert.include(actual, "___browserSync___.url = 'localhost:3000/browser-sync';");
9898
});
9999
it("should allow setting of the socket domain + namespace", function () {
100100
var options = merge({
@@ -107,7 +107,7 @@ describe("Connection utils", function () {
107107
}
108108
});
109109
var actual = utils.socketConnector(options);
110-
assert.include(actual, "___browserSync___.io('localhost:3000/shane', ___browserSync___.socketConfig);");
110+
assert.include(actual, "___browserSync___.url = 'localhost:3000/shane';");
111111
});
112112
it("should allow setting of the socket domain (fn)+ namespace", function () {
113113
var options = merge({
@@ -125,7 +125,7 @@ describe("Connection utils", function () {
125125
}
126126
});
127127
var actual = utils.socketConnector(options);
128-
assert.include(actual, "___browserSync___.io('http://localhost:3002/shane', ___browserSync___.socketConfig);");
128+
assert.include(actual, "___browserSync___.url = 'http://localhost:3002/shane';");
129129
});
130130
it("should allow setting of the socket namespace with fn (back compat)", function () {
131131
var options = merge({
@@ -142,6 +142,6 @@ describe("Connection utils", function () {
142142
}
143143
});
144144
var actual = utils.socketConnector(options);
145-
assert.include(actual, "___browserSync___.io('' + location.host + '/browser-sync', ___browserSync___.socketConfig);");
145+
assert.include(actual, "___browserSync___.url = '' + location.host + '/browser-sync';");
146146
});
147147
});

0 commit comments

Comments
 (0)