From 98dac060850f9cb6dcf9e7e6e7ad6e169e739fd7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 3 Feb 2017 10:50:33 -0700 Subject: [PATCH] allow templating --- README.md | 3 +++ bin/serve-https.js | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e935ada..0120cdd 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,9 @@ Options: * `-p ` - i.e. `sudo serve-https -p 443` (defaults to 80+443 or 8443) * `-d ` - i.e. `serve-https -d /tmp/` (defaults to `pwd`) + * you can use `:hostname` as a template for multiple directories + * Example A: `serve-https -d /srv/www/:hostname --sites localhost.foo.daplie.me,localhost.bar.daplie.me` + * Example B: `serve-https -d ./:hostname/public/ --sites localhost.foo.daplie.me,localhost.bar.daplie.me` * `-c ` - i.e. `server-https -c 'Hello, World! '` (defaults to directory index) * `--express-app ` - path to a file the exports an express-style app (`function (req, res, next) { ... }`) * `--livereload` - inject livereload into all html pages (see also: [fswatch](http://stackoverflow.com/a/13807906/151312)), but be careful if `` has thousands of files it will spike your CPU usage to 100% diff --git a/bin/serve-https.js b/bin/serve-https.js index e4fa3c5..6fde3bf 100755 --- a/bin/serve-https.js +++ b/bin/serve-https.js @@ -243,7 +243,7 @@ function run() { var argv = minimist(process.argv.slice(2)); var port = parseInt(argv.p || argv.port || argv._[0], 10) || httpsPort; var livereload = argv.livereload; - var defaultWebRoot = path.resolve(argv.d || argv._[1] || process.cwd()); + var defaultWebRoot = path.resolve(argv['default-web-root'] || argv.d || argv._[1] || process.cwd()); var content = argv.c; var letsencryptHost = argv['letsencrypt-certs']; @@ -356,13 +356,15 @@ function run() { return { name: servername // there should always be a path - , paths: nameparts.length && nameparts || [ defaultWebRoot ] + , paths: nameparts.length && nameparts || [ + defaultWebRoot.replace(/(:hostname|:servername)/g, servername) + ] }; }); } // TODO use arrays in all things opts._old_server_name = opts.sites[0].name; - opts.pubdir = defaultWebRoot; + opts.pubdir = defaultWebRoot.replace(/(:hostname|:servername).*/, ''); if (argv.p || argv.port || argv._[0]) { opts.manualPort = true;