From 62740eb969ffab5ea2ffae3fdb27202c755c14d0 Mon Sep 17 00:00:00 2001 From: dfsq Date: Tue, 22 Sep 2015 22:55:57 +0200 Subject: [PATCH] #182 Support for multiple static directories. --- src/cli/run.js | 4 +++- src/server/defaults.js | 6 ++++-- test/cli/fixtures/public2/styles/index.html | 1 + test/cli/index.js | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/cli/fixtures/public2/styles/index.html diff --git a/src/cli/run.js b/src/cli/run.js index 2af560aa5..627239a84 100644 --- a/src/cli/run.js +++ b/src/cli/run.js @@ -44,7 +44,9 @@ function createApp (source, object, routes, argv) { var defaults if (argv.static) { defaults = jsonServer.defaults({ - static: path.join(process.cwd(), argv.static) + static: [].concat(argv.static).map(function (staticPath) { + return path.join(process.cwd(), staticPath) + }) }) } else { defaults = jsonServer.defaults() diff --git a/src/server/defaults.js b/src/server/defaults.js index 3b1646e07..3734c6665 100644 --- a/src/server/defaults.js +++ b/src/server/defaults.js @@ -12,7 +12,7 @@ module.exports = function (opts) { userDir : defaultDir - opts = opts || { static: staticDir } + opts = opts || { static: [staticDir] } var arr = [] @@ -33,7 +33,9 @@ module.exports = function (opts) { } // Serve static files - arr.push(express.static(opts.static)) + opts.static.forEach(function (staticPath) { + arr.push(express.static(staticPath)) + }) // No cache for IE // https://support.microsoft.com/en-us/kb/234067 diff --git a/test/cli/fixtures/public2/styles/index.html b/test/cli/fixtures/public2/styles/index.html new file mode 100644 index 000000000..40816a2b5 --- /dev/null +++ b/test/cli/fixtures/public2/styles/index.html @@ -0,0 +1 @@ +Hi \ No newline at end of file diff --git a/test/cli/index.js b/test/cli/index.js index c8c968369..0abd475f4 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -124,6 +124,22 @@ describe('cli', function () { }) + describe('db.json -s fixtures/public -s fixtures/public2', function () { + + beforeEach(function (done) { + child = cli([dbFile, '-s', 'fixtures/public', '-s', 'fixtures/public2']) + serverReady(PORT, done) + }) + + it('should serve fixtures/public', function (done) { + request.get('/').expect(/Hello/, done) + }) + + it('should serve fixtures/public2', function (done) { + request.get('/styles/').expect(/Hi/, done) + }) + }) + // FIXME test fails on OS X and maybe on Windows // But manually updating db.json works... if (os.platform() === 'linux') {