-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rewrite): Allow addtional HTML rewrite rules through server + pr…
…oxy modes to help with #514
- Loading branch information
1 parent
2371d22
commit 76ae686
Showing
6 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../../index"); | ||
|
||
var connect = require("connect"); | ||
var serveStatic = require("serve-static"); | ||
var request = require("supertest"); | ||
var assert = require("chai").assert; | ||
|
||
describe("E2E proxy test with rewrite rules", function () { | ||
|
||
var instance, server, options; | ||
|
||
before(function (done) { | ||
|
||
browserSync.reset(); | ||
|
||
var app = connect(); | ||
app.use(serveStatic("./test/fixtures")); | ||
server = app.listen(); | ||
var proxytarget = "http://localhost:" + server.address().port; | ||
|
||
var config = { | ||
proxy: proxytarget, | ||
logLevel: "silent", | ||
open: false, | ||
rewriteRules: [ | ||
{ | ||
match: /Forms/g, | ||
fn: function () { | ||
return "Shane's forms"; | ||
} | ||
} | ||
] | ||
}; | ||
|
||
instance = browserSync.init([], config, function (err, bs) { | ||
options = bs.options; | ||
done(); | ||
}).instance; | ||
}); | ||
|
||
after(function () { | ||
instance.cleanup(); | ||
server.close(); | ||
}); | ||
|
||
it("serves files with HTML rewritten", function (done) { | ||
|
||
request(instance.server) | ||
.get("/index.html") | ||
.set("accept", "text/html") | ||
.expect(200) | ||
.end(function (err, res) { | ||
assert.include(res.text, "Shane's forms"); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../../index"); | ||
|
||
var request = require("supertest"); | ||
var assert = require("chai").assert; | ||
|
||
describe("E2E server test with rewrite rules", function () { | ||
|
||
var instance; | ||
|
||
before(function (done) { | ||
|
||
browserSync.reset(); | ||
|
||
var config = { | ||
server: { | ||
baseDir: "test/fixtures" | ||
}, | ||
rewriteRules: [ | ||
{ | ||
match: /Forms/g, | ||
fn: function () { | ||
return "Shane's forms"; | ||
} | ||
} | ||
], | ||
logLevel: "silent", | ||
open: false | ||
}; | ||
|
||
instance = browserSync.init(config, done).instance; | ||
}); | ||
|
||
after(function () { | ||
instance.cleanup(); | ||
}); | ||
|
||
it("serves files with HTML rewritten", function (done) { | ||
|
||
request(instance.server) | ||
.get("/index.html") | ||
.set("accept", "text/html") | ||
.expect(200) | ||
.end(function (err, res) { | ||
assert.include(res.text, "Shane's forms"); | ||
done(); | ||
}); | ||
}); | ||
}); |