Skip to content

Commit 99b8dc0

Browse files
committed
Make initial app middleware generic
1 parent 75d644a commit 99b8dc0

7 files changed

Lines changed: 35 additions & 19 deletions

File tree

lib/default-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ module.exports = {
194194
whitelist: [],
195195
blacklist: [],
196196
rule: {
197-
match: /<body[^>]*>/i,
197+
match: /$/,
198198
fn: function (snippet, match) {
199199
return match + snippet;
200200
}

lib/server/proxy-server.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ module.exports = function createProxyServer (bs, scripts) {
6969
var proxyRes = getProxyResFunctions(opt.get("proxyRes"), opt);
7070
var app = utils.getBaseApp(bs, scripts);
7171

72-
/**
73-
* Add the proxy Middleware to the end of the stack
74-
*/
7572
app.stack.push({
7673
id: "Browsersync Proxy",
7774
route: opt.get("route"),

lib/server/utils.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,32 @@ var utils = {
115115
getBaseApp: function (bs, scripts) {
116116

117117
var app = connect();
118-
var rule = require("./proxy-utils").rewriteLinks(bs.options.getIn(["proxy", "url"]).toJS());
119-
120-
bs.snippetMw.opts.rules.push(rule);
121-
122-
/**
123-
* Add the snippet middleware to the front of the stack
124-
*/
125-
app.use(bs.snippetMw.middleware);
126118

127119
/**
128-
* Serve the Client-side JS from both version and static paths
120+
* Add the proxy Middleware to the end of the stack
129121
*/
130-
app.use(bs.options.getIn(["scriptPaths", "versioned"]), scripts)
131-
.use(bs.options.getIn(["scriptPaths", "path"]), scripts);
122+
app.stack.push(
123+
{
124+
id: "Browsersync IE8 Support",
125+
route: "",
126+
handle: utils.handleOldIE
127+
},
128+
{
129+
id: "Browsersync Response Modifier",
130+
route: "",
131+
handle: utils.getSnippetMiddleware(bs)
132+
},
133+
{
134+
id: "Browsersync Client - versioned",
135+
route: bs.options.getIn(["scriptPaths", "versioned"]),
136+
handle: scripts
137+
},
138+
{
139+
id: "Browsersync Client",
140+
route: bs.options.getIn(["scriptPaths", "path"]),
141+
handle: scripts
142+
}
143+
);
132144

133145
/**
134146
* Add user-provided middlewares
@@ -138,6 +150,13 @@ var utils = {
138150
});
139151

140152
return app;
153+
},
154+
getSnippetMiddleware: function (bs) {
155+
if (bs.options.get("proxy")) {
156+
var rule = require("./proxy-utils").rewriteLinks(bs.options.getIn(["proxy", "url"]).toJS());
157+
bs.snippetMw.opts.rules.push(rule);
158+
}
159+
return bs.snippetMw.middleware;
141160
}
142161
};
143162

test/specs/e2e/proxy/e2e.proxy.proxy.options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("E2E proxy test with `proxyOptions`", function () {
4343

4444
it("sets options for node-http-proxy", function (done) {
4545

46-
var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");
46+
var expected = app.html + bs.options.get("snippet");
4747
var headers;
4848

4949
app.app.stack.unshift({

test/specs/e2e/proxy/e2e.proxy.req.headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("E2E proxy test with custom req headers", function () {
4848

4949
it("sets custom headers on proxy reqs", function (done) {
5050

51-
var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");
51+
var expected = app.html + bs.options.get("snippet");
5252
var headers;
5353

5454
app.app.stack.unshift({

test/specs/e2e/proxy/e2e.proxy.req.headers.obj.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("E2E proxy test with custom req headers as object", function () {
4646

4747
it("sets custom headers on proxy reqs from an object", function (done) {
4848

49-
var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");
49+
var expected = app.html + bs.options.get("snippet");
5050
var headers;
5151

5252
app.app.stack.unshift({

test/specs/e2e/proxy/e2e.proxy.secure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("E2E TLS proxy test", function () {
4545

4646
assert.isString(bs.options.get("snippet"));
4747

48-
var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");
48+
var expected = app.html + bs.options.get("snippet");
4949

5050
request(bs.options.getIn(["urls", "local"]))
5151
.get("/index.html")

0 commit comments

Comments
 (0)