Skip to content

Commit cb1b32f

Browse files
committed
Fix historyApiFallback, again.
The problem earlier with the fix in #627 was that it broke serving files without extensions (or with `disableDotRule`). This passed the test because the `disableDotRule: true` was removed; without this the test will always succeed because without this rule, a request like `/other.html` will always go directly to the file.
1 parent 0d3a707 commit cb1b32f

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/Server.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,11 @@ function Server(compiler, options) {
227227
}
228228
},
229229

230-
contentBase: function() {
230+
contentBaseFiles: function() {
231231
if(Array.isArray(contentBase)) {
232232
contentBase.forEach(function(item) {
233233
app.get("*", express.static(item));
234234
});
235-
contentBase.forEach(function(item) {
236-
app.get("*", serveIndex(item));
237-
});
238235
} else if(/^(https?:)?\/\//.test(contentBase)) {
239236
// Redirect every request to contentBase
240237
app.get("*", function(req, res) {
@@ -253,7 +250,17 @@ function Server(compiler, options) {
253250
});
254251
} else {
255252
// route content request
256-
app.get("*", express.static(contentBase, options.staticOptions), serveIndex(contentBase));
253+
app.get("*", express.static(contentBase, options.staticOptions));
254+
}
255+
},
256+
257+
contentBaseIndex: function() {
258+
if(Array.isArray(contentBase)) {
259+
contentBase.forEach(function(item) {
260+
app.get("*", serveIndex(item));
261+
});
262+
} else if(!/^(https?:)?\/\//.test(contentBase) && typeof contentBase !== "number") {
263+
app.get("*", serveIndex(contentBase));
257264
}
258265
},
259266

@@ -279,11 +286,13 @@ function Server(compiler, options) {
279286
var defaultFeatures = ["setup", "headers", "middleware"];
280287
if(options.proxy)
281288
defaultFeatures.push("proxy", "middleware");
289+
if(options.contentBase !== false)
290+
defaultFeatures.push("contentBaseFiles");
282291
if(options.historyApiFallback)
283292
defaultFeatures.push("historyApiFallback", "middleware");
284293
defaultFeatures.push("magicHtml");
285294
if(options.contentBase !== false)
286-
defaultFeatures.push("contentBase");
295+
defaultFeatures.push("contentBaseIndex");
287296
// compress is placed last and uses unshift so that it will be the first middleware used
288297
if(options.compress)
289298
defaultFeatures.unshift("compress");

test/HistoryApiFallback.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("HistoryApiFallback", function() {
5353
req = request(server.app);
5454
});
5555

56-
it("historyApiFallback should take preference above magicHtml", function(done) {
56+
it("historyApiFallback should take preference above directory index", function(done) {
5757
req.get("/")
5858
.accept("html")
5959
.expect(200, /Foobar/, done);
@@ -66,9 +66,9 @@ describe("HistoryApiFallback", function() {
6666
});
6767

6868
it("contentBase file should take preference above historyApiFallback", function(done) {
69-
req.get("/other.html")
69+
req.get("/random-file")
7070
.accept("html")
71-
.expect(200, /Other file/, done);
71+
.expect(200, /Random file/, done);
7272
});
7373
});
7474

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Random file

0 commit comments

Comments
 (0)