From 92dc1503ac12c64997a5711408eddaa67da719f7 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 27 Mar 2015 17:23:47 -0400 Subject: [PATCH 1/5] add serve-static 'extensions' option to server --- lib/options.js | 3 +++ lib/server/static-server.js | 3 ++- lib/server/utils.js | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/options.js b/lib/options.js index 9bed9600f..8f21d468c 100644 --- a/lib/options.js +++ b/lib/options.js @@ -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")); + } } } diff --git a/lib/server/static-server.js b/lib/server/static-server.js index f6936e5b9..5cbcfaee2 100644 --- a/lib/server/static-server.js +++ b/lib/server/static-server.js @@ -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(); @@ -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 diff --git a/lib/server/utils.js b/lib/server/utils.js index f06dcecbb..74a8ae864 100644 --- a/lib/server/utils.js +++ b/lib/server/utils.js @@ -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})); } } }, From 9edea1c658755cbfd99d56cb9d43e73cc856f2e8 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 27 Mar 2015 18:13:26 -0400 Subject: [PATCH 2/5] add extensions option to cli --- lib/cli/cli-options.js | 4 ++++ lib/cli/opts.json | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/cli/cli-options.js b/lib/cli/cli-options.js index ea5594462..eb895c3c6 100644 --- a/lib/cli/cli-options.js +++ b/lib/cli/cli-options.js @@ -93,6 +93,10 @@ opts.callbacks = { if (argv.directory) { obj.directory = true; } + + if (argv.extensions) { + obj.extensions = argv.extensions; + } } return Immutable.fromJS(obj); diff --git a/lib/cli/opts.json b/lib/cli/opts.json index 67b2306f3..37ef67ccc 100644 --- a/lib/cli/opts.json +++ b/lib/cli/opts.json @@ -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", From 7cb64ff6380cb41ea6b9304f824fc2a21ce8006e Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 27 Mar 2015 18:17:36 -0400 Subject: [PATCH 3/5] test extensions option --- test/specs/e2e/cli/e2e.cli.server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/specs/e2e/cli/e2e.cli.server.js b/test/specs/e2e/cli/e2e.cli.server.js index b8e354917..5e6c33bb0 100644 --- a/test/specs/e2e/cli/e2e.cli.server.js +++ b/test/specs/e2e/cli/e2e.cli.server.js @@ -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) { @@ -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"); }); }); From 4a4a7c535fa8ab789dfcc90bfb99c2919c33f5dc Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 27 Mar 2015 18:42:26 -0400 Subject: [PATCH 4/5] fix lint --- gulpfile.js | 10 +++++----- lib/server/static-server.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3cb20107c..1e1308f56 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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", diff --git a/lib/server/static-server.js b/lib/server/static-server.js index 5cbcfaee2..021e00559 100644 --- a/lib/server/static-server.js +++ b/lib/server/static-server.js @@ -16,7 +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 extensions = server.get("extensions") || ["html", "htm"]; var app = connect(); From aee5c981be4739227c5eeef3cd82f3a63d66299c Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 27 Mar 2015 19:49:56 -0400 Subject: [PATCH 5/5] replace duplicate test with test for extensions option --- test/specs/cli/cli.options.server.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/specs/cli/cli.options.server.js b/test/specs/cli/cli.options.server.js index 1f7f7c2a1..15be7d741 100644 --- a/test/specs/cli/cli.options.server.js +++ b/test/specs/cli/cli.options.server.js @@ -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" @@ -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 @@ -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,