Skip to content

Commit 0d3a707

Browse files
mac2000SpaceK33z
authored andcommitted
fix for #625 broken historyApiFallback (#627)
* fix for #625 broken historyApiFallback * historyApiFallback rewrite option tests added
1 parent 591ae97 commit 0d3a707

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/Server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ function Server(compiler, options) {
279279
var defaultFeatures = ["setup", "headers", "middleware"];
280280
if(options.proxy)
281281
defaultFeatures.push("proxy", "middleware");
282+
if(options.historyApiFallback)
283+
defaultFeatures.push("historyApiFallback", "middleware");
282284
defaultFeatures.push("magicHtml");
283285
if(options.contentBase !== false)
284286
defaultFeatures.push("contentBase");
285-
if(options.historyApiFallback)
286-
defaultFeatures.push("historyApiFallback", "middleware");
287287
// compress is placed last and uses unshift so that it will be the first middleware used
288288
if(options.compress)
289289
defaultFeatures.unshift("compress");

test/HistoryApiFallback.test.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ describe("HistoryApiFallback", function() {
4747
server = helper.start(config2, {
4848
contentBase: path.join(__dirname, "fixtures/historyapifallback-2-config"),
4949
historyApiFallback: {
50-
index: "/bar.html",
51-
disableDotRule: true
50+
index: "/bar.html"
5251
}
5352
}, done);
5453
req = request(server.app);
@@ -72,4 +71,43 @@ describe("HistoryApiFallback", function() {
7271
.expect(200, /Other file/, done);
7372
});
7473
});
74+
75+
describe("as object with contentBase and rewrites", function() {
76+
before(function(done) {
77+
server = helper.start(config2, {
78+
contentBase: path.join(__dirname, "fixtures/historyapifallback-2-config"),
79+
historyApiFallback: {
80+
rewrites: [
81+
{
82+
from: /other/,
83+
to: "/other.html"
84+
},
85+
{
86+
from: /.*/,
87+
to: "/bar.html"
88+
}
89+
]
90+
}
91+
}, done);
92+
req = request(server.app);
93+
});
94+
95+
it("historyApiFallback respect rewrites for index", function(done) {
96+
req.get("/")
97+
.accept("html")
98+
.expect(200, /Foobar/, done);
99+
});
100+
101+
it("historyApiFallback respect rewrites and shows index for unknown urls", function(done) {
102+
req.get("/acme")
103+
.accept("html")
104+
.expect(200, /Foobar/, done);
105+
});
106+
107+
it("historyApiFallback respect any other specified rewrites", function(done) {
108+
req.get("/other")
109+
.accept("html")
110+
.expect(200, /Other file/, done);
111+
});
112+
});
75113
});

0 commit comments

Comments
 (0)