From 63208ac8bf53924d066cc44d15b7fc13b41404f3 Mon Sep 17 00:00:00 2001 From: Aral Balkan Date: Tue, 4 Feb 2020 14:17:09 +0000 Subject: [PATCH] Add multiple roots This adds multiple roots support so that you can serve multiple directories under a single mount point (Option 1 in #6). --- lib/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3193d1d..b6200a2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,7 +10,7 @@ var startup = Date.now() module.exports = function(root, opts) { - if (typeof root == 'object') { + if (typeof root == 'object' && !(root instanceof Array)) { opts = root root = opts.root } @@ -93,7 +93,15 @@ module.exports = function(root, opts) { } if (root) { - fn.use(serve(root, opts)) + if (root instanceof Array) { + // Multiple roots. + root.forEach(r => { + fn.use(serve(r, Object.create(opts))) + }) + } else { + // Single root. + fn.use(serve(root, opts)) + } } return fn