Skip to content

Commit 34816a7

Browse files
committed
fix(server): set index correctly if serveStaticOptions: {index: <path>} given
1 parent 182832e commit 34816a7

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

lib/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ function setServerOpts(item) {
123123
index: indexarg
124124
}));
125125
} else {
126-
item.setIn(optPath.concat(["index"]), indexarg);
126+
if (!item.hasIn(optPath.concat(["index"]))) {
127+
item.setIn(optPath.concat(["index"]), indexarg);
128+
}
127129
}
128130

129131
// cli extensions
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use strict";
2+
3+
var browserSync = require("../../../../index");
4+
var request = require("supertest");
5+
var assert = require("chai").assert;
6+
7+
describe("E2E server test with serve static options", function () {
8+
9+
it("sets the index of serve-static", function (done) {
10+
11+
browserSync.reset();
12+
13+
var config = {
14+
server: {
15+
baseDir: "test/fixtures",
16+
serveStaticOptions: {
17+
index: "inputs.html"
18+
}
19+
},
20+
logLevel: "silent",
21+
open: false
22+
};
23+
24+
browserSync.create().init(config, function (err, bs) {
25+
assert.equal(bs.options.getIn(["server", "serveStaticOptions", "index"]), "inputs.html");
26+
request(bs.server)
27+
.get("/")
28+
.expect(200)
29+
.end(function (err, res) {
30+
assert.deepEqual(
31+
require("fs").readFileSync("test/fixtures/inputs.html", "utf-8"),
32+
res.text
33+
);
34+
bs.cleanup();
35+
done();
36+
});
37+
});
38+
});
39+
it("sets uses the default for serve static index", function (done) {
40+
41+
browserSync.reset();
42+
43+
var config = {
44+
server: {
45+
baseDir: "test/fixtures",
46+
serveStaticOptions: {}
47+
},
48+
logLevel: "silent",
49+
open: false
50+
};
51+
52+
browserSync.create().init(config, function (err, bs) {
53+
assert.equal(bs.options.getIn(["server", "serveStaticOptions", "index"]), "index.html");
54+
request(bs.server)
55+
.get("/")
56+
.expect(200)
57+
.end(function (err, res) {
58+
assert.deepEqual(
59+
require("fs").readFileSync("test/fixtures/index.html", "utf-8"),
60+
res.text
61+
);
62+
bs.cleanup();
63+
done();
64+
});
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)