Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve-static option: 'extensions' #539

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ gulp.task("sass", function () {
*/
gulp.task("browser-sync", function () {

// var clientScript = require("/Users/shakyshane/Sites/browser-sync-modules/browser-sync-client/index");
//
// browserSync.use("client:script", clientScript.middleware, function (err) {
// console.log(err);
// });
// var clientScript = require("/Users/shakyshane/Sites/browser-sync-modules/browser-sync-client/index");
//
// browserSync.use("client:script", clientScript.middleware, function (err) {
// console.log(err);
// });

browserSync({
server: "test/fixtures",
Expand Down
4 changes: 4 additions & 0 deletions lib/cli/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ opts.callbacks = {
if (argv.directory) {
obj.directory = true;
}

if (argv.extensions) {
obj.extensions = argv.extensions;
}
}

return Immutable.fromJS(obj);
Expand Down
1 change: 1 addition & 0 deletions lib/cli/opts.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"startPath": "Specify the start path for the opened browser",
"https": "Enable SSL for local development",
"directory": "Show a directory listing for the server",
"extensions": "Specify file extension fallbacks",
"proxy": "Proxy an existing server",
"xip": "Use xip.io domain routing",
"tunnel": "Use a public URL",
Expand Down
3 changes: 3 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ function setServerOpts(item) {
if (item.get("index")) {
item.setIn(["server", "index"], item.get("index"));
}
if (item.get("extensions")) {
item.setIn(["server", "extensions"], item.get("extensions"));
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/server/static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function createServer (bs, scripts) {
var middleware = options.get("middleware");
var index = server.get("index") || "index.html";
var basedir = server.get("baseDir");
var extensions = server.get("extensions") || ["html", "htm"];

var app = connect();

Expand Down Expand Up @@ -56,7 +57,7 @@ module.exports = function createServer (bs, scripts) {
/**
* Add Serve static middlewares
*/
utils.addBaseDir(app, basedir, index);
utils.addBaseDir(app, basedir, index, extensions);

/**
* Add further Serve static middlewares for routes
Expand Down
6 changes: 3 additions & 3 deletions lib/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ var utils = {
* @param base
* @param index
*/
addBaseDir: function (app, base, index) {
addBaseDir: function (app, base, index, extensions) {

if (isList(base)) {
base.forEach(function (item) {
app.use(serveStatic(filePath.resolve(item), {index: index}));
app.use(serveStatic(filePath.resolve(item), {index: index, extensions: extensions}));
});
} else {
if (_.isString(base)) {
app.use(serveStatic(filePath.resolve(base), {index: index}));
app.use(serveStatic(filePath.resolve(base), {index: index, extensions: extensions}));
}
}
},
Expand Down
20 changes: 11 additions & 9 deletions test/specs/cli/cli.options.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("CLI: Options: Merging Server Options", function () {
assert.equal(imm.getIn(["server", "index"]), "index.htm");
assert.isFunction(imm.getIn(["server", "middleware"]));
});
it("can merge cli flags into object", function () {
it("can merge cli server, index flags into object", function () {
var argv = {
server: true,
index: "index.htm"
Expand All @@ -65,7 +65,7 @@ describe("CLI: Options: Merging Server Options", function () {
index: "index.htm"
});
});
it("can merge cli flags into object", function () {
it("can merge cli server, directory flags into object", function () {
var argv = {
server: true,
directory: true
Expand All @@ -76,18 +76,20 @@ describe("CLI: Options: Merging Server Options", function () {
directory: true
});
});
it("can merge cli flags into object", function () {
it("can merge cli server, index, extensions flags into object", function () {
var argv = {
server: true,
directory: true
server: "app",
index: "file.html",
extensions: ["html", "json"]
};
var imm = merge({}, argv);
var imm = merge({server: "app"}, argv);
assert.deepEqual(imm.get("server").toJS(), {
baseDir: "./",
directory: true
baseDir: "app",
index: "file.html",
extensions: ["html", "json"]
});
});
it("can merge cli flags into object", function () {
it("can merge cli server, directory, index flags into object", function () {
var argv = {
server: "app",
directory: true,
Expand Down
4 changes: 3 additions & 1 deletion test/specs/e2e/cli/e2e.cli.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe("E2E CLI server test with directory listing/index ", function () {
online: false,
logLevel: "silent",
directory: true,
index: "index.htm"
index: "index.htm",
extensions: "html"
}
},
cb: function (err, bs) {
Expand All @@ -89,5 +90,6 @@ describe("E2E CLI server test with directory listing/index ", function () {
it("Sets the correct server options", function () {
assert.equal(instance.options.getIn(["server", "directory"]), true);
assert.equal(instance.options.getIn(["server", "index"]), "index.htm");
assert.equal(instance.options.getIn(["server", "extensions"]), "html");
});
});