diff --git a/lib/connect-utils.js b/lib/connect-utils.js
index 1ff623ca1..4ef366920 100644
--- a/lib/connect-utils.js
+++ b/lib/connect-utils.js
@@ -69,41 +69,30 @@ var connectUtils = {
},
getConnectionUrl: function (options) {
- var protocol = "";
- var string = "'%protocol%' + location.%host% + '%ns%'";
- var socketOpts = connectUtils.resolveSocketOptions(options);
+ var protocol = "";
+ var withHostnamePort = "'{protocol}' + location.hostname + ':{port}{ns}'"; //
+ var withHost = "'{protocol}' + location.host + '{ns}'"; //
+ var withDomain = "'{domain}{ns}'";
+
+ // default use-case is server/proxy
+ var string = withHost;
if (options.get("mode") === "snippet") {
protocol = options.get("scheme") + "://";
+ string = withHostnamePort;
}
- return string
- .replace("%protocol%", protocol)
- .replace("%host%", socketOpts.host)
- .replace("%ns%", socketOpts.namespace);
- },
- /**
- * @param options
- * @returns {{host: string, namespace: string}}
- */
- resolveSocketOptions: function (options) {
+ var socketOpts = options.get('socket');
- var socket = options.get("socket");
- var namespace = socket.get("namespace");
- var external = options.get("mode") === "snippet";
-
- return {
- host: external
- ? "hostname"
- : "host",
- namespace: (function (external) {
-
- return external
- ? [":", options.get("port"), namespace].join("")
- : namespace;
+ if (socketOpts.has('domain')) {
+ string = withDomain;
+ }
- })(external)
- };
+ return string
+ .replace("{protocol}", protocol)
+ .replace("{port}", options.get("port"))
+ .replace("{domain}", socketOpts.get("domain"))
+ .replace("{ns}", socketOpts.get("namespace"));
},
/**
* @param {Object} [options]
diff --git a/lib/templates/script-tags.tmpl b/lib/templates/script-tags.tmpl
index 0c3c945ac..5a6d4fc58 100644
--- a/lib/templates/script-tags.tmpl
+++ b/lib/templates/script-tags.tmpl
@@ -1,3 +1,3 @@
diff --git a/package.json b/package.json
index b82c58abc..d3f2a29f8 100644
--- a/package.json
+++ b/package.json
@@ -75,7 +75,7 @@
"istanbul-coveralls": "^1.0.3",
"mocha": "^2.2.5",
"q": "^1.4.1",
- "request": "^2.57.0",
+ "request": "^2.58.0",
"sinon": "^1.15.3",
"slugify": "^0.1.1",
"socket.io-client": "^1.3.5",
diff --git a/test/specs/utils/utils.connect.js b/test/specs/utils/utils.connect.js
index 6f80b58d0..affc82103 100644
--- a/test/specs/utils/utils.connect.js
+++ b/test/specs/utils/utils.connect.js
@@ -4,6 +4,10 @@ var utils = require("../../../lib/connect-utils");
var merge = require("../../../lib/cli/cli-options").merge;
var assert = require("chai").assert;
+// server,proxy: ['' + location.host + '/browser-sync']
+// snippet: ['http://' + location.hostname + ':3000/browser-sync']
+// domain: ['/browser-sync']
+
describe("Connection utils", function () {
var options;
beforeEach(function () {
@@ -73,4 +77,16 @@ describe("Connection utils", function () {
var actual = utils.socketConnector(options);
assert.include(actual, "'https://' + location.hostname + ':4002/browser-sync'");
});
+ it("should allow setting of the socket domain", function () {
+ var options = merge({
+ port: 3000,
+ server: "test/fixtures",
+ mode: "server",
+ socket: {
+ domain: 'localhost:3000'
+ }
+ });
+ var actual = utils.socketConnector(options);
+ assert.include(actual, "___browserSync___.io('localhost:3000/browser-sync', ___browserSync___.socketConfig);");
+ });
});