Skip to content

Commit 2a61860

Browse files
authored
Merge pull request #986 from nightwing/master
Use https url for socket when page is loaded over https
2 parents eef1cf3 + 7735b1b commit 2a61860

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
@@ -53,7 +53,7 @@ describe("E2E Socket namespace test - given a string", function () {
5353
.get(instance.options.getIn(["scriptPaths", "path"]))
5454
.expect(200)
5555
.end(function (err, res) {
56-
assert.include(res.text, "io('' + location.host + '/TEST',");
56+
assert.include(res.text, "___browserSync___.url = '' + location.host + '/TEST';");
5757
done();
5858
});
5959
});

test/specs/utils/utils.connect.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("Connection snippetUtils", function () {
9292
}
9393
});
9494
var actual = utils.socketConnector(options);
95-
assert.include(actual, "___browserSync___.io('localhost:3000/browser-sync', ___browserSync___.socketConfig);");
95+
assert.include(actual, "___browserSync___.url = 'localhost:3000/browser-sync';");
9696
});
9797
it("should allow setting of the socket domain + namespace", function () {
9898
var options = merge({
@@ -105,7 +105,7 @@ describe("Connection snippetUtils", function () {
105105
}
106106
});
107107
var actual = utils.socketConnector(options);
108-
assert.include(actual, "___browserSync___.io('localhost:3000/shane', ___browserSync___.socketConfig);");
108+
assert.include(actual, "___browserSync___.url = 'localhost:3000/shane';");
109109
});
110110
it("should allow setting of the socket domain (fn)+ namespace", function () {
111111
var options = merge({
@@ -123,7 +123,7 @@ describe("Connection snippetUtils", function () {
123123
}
124124
});
125125
var actual = utils.socketConnector(options);
126-
assert.include(actual, "___browserSync___.io('http://localhost:3002/shane', ___browserSync___.socketConfig);");
126+
assert.include(actual, "___browserSync___.url = 'http://localhost:3002/shane';");
127127
});
128128
it("should allow setting of the socket namespace with fn (back compat)", function () {
129129
var options = merge({
@@ -140,7 +140,7 @@ describe("Connection snippetUtils", function () {
140140
}
141141
});
142142
var actual = utils.socketConnector(options);
143-
assert.include(actual, "___browserSync___.io('' + location.host + '/browser-sync', ___browserSync___.socketConfig);");
143+
assert.include(actual, "___browserSync___.url = '' + location.host + '/browser-sync';");
144144
});
145145
it("E2E Should allow setting of socket.domain + script.domain as strings", function (done) {
146146
bs.reset();

0 commit comments

Comments
 (0)