Skip to content

Commit 62740eb

Browse files
committed
#182 Support for multiple static directories.
1 parent 75e5b3b commit 62740eb

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/cli/run.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function createApp (source, object, routes, argv) {
4444
var defaults
4545
if (argv.static) {
4646
defaults = jsonServer.defaults({
47-
static: path.join(process.cwd(), argv.static)
47+
static: [].concat(argv.static).map(function (staticPath) {
48+
return path.join(process.cwd(), staticPath)
49+
})
4850
})
4951
} else {
5052
defaults = jsonServer.defaults()

src/server/defaults.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function (opts) {
1212
userDir :
1313
defaultDir
1414

15-
opts = opts || { static: staticDir }
15+
opts = opts || { static: [staticDir] }
1616

1717
var arr = []
1818

@@ -33,7 +33,9 @@ module.exports = function (opts) {
3333
}
3434

3535
// Serve static files
36-
arr.push(express.static(opts.static))
36+
opts.static.forEach(function (staticPath) {
37+
arr.push(express.static(staticPath))
38+
})
3739

3840
// No cache for IE
3941
// https://support.microsoft.com/en-us/kb/234067
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi

test/cli/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ describe('cli', function () {
124124

125125
})
126126

127+
describe('db.json -s fixtures/public -s fixtures/public2', function () {
128+
129+
beforeEach(function (done) {
130+
child = cli([dbFile, '-s', 'fixtures/public', '-s', 'fixtures/public2'])
131+
serverReady(PORT, done)
132+
})
133+
134+
it('should serve fixtures/public', function (done) {
135+
request.get('/').expect(/Hello/, done)
136+
})
137+
138+
it('should serve fixtures/public2', function (done) {
139+
request.get('/styles/').expect(/Hi/, done)
140+
})
141+
})
142+
127143
// FIXME test fails on OS X and maybe on Windows
128144
// But manually updating db.json works...
129145
if (os.platform() === 'linux') {

0 commit comments

Comments
 (0)