Skip to content

Commit b4db6f9

Browse files
committed
feat: Added --localOnly flag
1 parent 21edcc1 commit b4db6f9

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

lib/connect-utils.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ var connectUtils = {
2828
*/
2929
var scriptSrc = (function () {
3030

31+
if (options.get("localOnly")) {
32+
return [
33+
options.get("scheme"),
34+
"://localhost:",
35+
options.get("port"),
36+
scriptPath
37+
].join("");
38+
}
39+
3140
/**
32-
* First, was 'scriptPath' set? if so the user wanted full control over the
41+
* First, was "scriptPath" set? if so the user wanted full control over the
3342
* script tag output
3443
*
3544
*/
@@ -38,7 +47,7 @@ var connectUtils = {
3847
}
3948

4049
/**
41-
* Next, if 'script.domain' was given, allow that + the path to the JS file
50+
* Next, if "script.domain" was given, allow that + the path to the JS file
4251
* eg:
4352
* script.domain=localhost:3000
4453
* -> localhost:3000/browser-sync/browser-sync-client.js
@@ -76,7 +85,7 @@ var connectUtils = {
7685
* Decide which template shall be used to generate the script tags
7786
*/
7887
var template = (function () {
79-
if (scriptDomain) {
88+
if (scriptDomain || options.get("localOnly")) {
8089
return config.templates.scriptTagSimple;
8190
}
8291
return config.templates.scriptTag;
@@ -167,6 +176,14 @@ var connectUtils = {
167176
* Ensure socket.domain is always a string (for noop replacements later)
168177
*/
169178
socketOpts.domain = (function () {
179+
if (options.get("localOnly")) {
180+
string = withDomain;
181+
return [
182+
options.get("scheme"),
183+
"://localhost:",
184+
options.get("port")
185+
].join("");
186+
}
170187
if (socketOpts.domain) {
171188
string = withDomain;
172189
/**

lib/default-config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ module.exports = {
383383
*/
384384
host: null,
385385

386+
/**
387+
* Support environments where dynamic hostnames are not required
388+
* (ie: electron)
389+
* @property localOnly
390+
* @type Boolean
391+
* @default false
392+
*/
393+
localOnly: false,
394+
386395
/**
387396
* @property codeSync
388397
* @type Boolean

test/specs/utils/utils.connect.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ var req = require("supertest");
66
var merge = require("../../../lib/cli/cli-options").merge;
77
var assert = require("chai").assert;
88

9-
// server,proxy: ['' + location.host + '/browser-sync']
10-
// snippet: ['http://' + location.hostname + ':3000/browser-sync']
11-
// domain: ['<domain>/browser-sync']
12-
139
describe("Connection snippetUtils", function () {
1410
var options;
1511
beforeEach(function () {
@@ -173,6 +169,29 @@ describe("Connection snippetUtils", function () {
173169
});
174170
});
175171
});
172+
it("E2E Should allow setting of socket.domain + script.domain as strings when using --localOnly flag", function (done) {
173+
bs.reset();
174+
bs.create().init({
175+
ui: false,
176+
online: false,
177+
logLevel: "silent",
178+
localOnly: true
179+
}, function (err, bs) {
180+
var port = bs.options.get("port");
181+
assert.include(bs.options.get("snippet"), "<script async id=\"__bs_script__\" src=\"http://localhost:" + port + "/browser-sync");
182+
183+
var expected = "___browserSync___.io('http://localhost:" + port + "/browser-sync'";
184+
185+
req(bs.server)
186+
.get(bs.options.getIn(["scriptPaths", "path"]))
187+
.expect(200)
188+
.end(function (err, res) {
189+
assert.include(res.text, expected, "Socket domain updated in response");
190+
bs.cleanup();
191+
done();
192+
});
193+
});
194+
});
176195
it("E2E Should allow setting of script.domain as functions", function (done) {
177196
bs.reset();
178197
bs.create().init({

0 commit comments

Comments
 (0)