allow templating

This commit is contained in:
AJ ONeal 2017-02-03 10:50:33 -07:00
parent e7022c8bd4
commit 98dac06085
2 changed files with 8 additions and 3 deletions

View File

@ -69,6 +69,9 @@ Options:
* `-p <port>` - i.e. `sudo serve-https -p 443` (defaults to 80+443 or 8443) * `-p <port>` - i.e. `sudo serve-https -p 443` (defaults to 80+443 or 8443)
* `-d <dirpath>` - i.e. `serve-https -d /tmp/` (defaults to `pwd`) * `-d <dirpath>` - 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 <content>` - i.e. `server-https -c 'Hello, World! '` (defaults to directory index) * `-c <content>` - i.e. `server-https -c 'Hello, World! '` (defaults to directory index)
* `--express-app <path>` - path to a file the exports an express-style app (`function (req, res, next) { ... }`) * `--express-app <path>` - 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 `<dirpath>` has thousands of files it will spike your CPU usage to 100% * `--livereload` - inject livereload into all html pages (see also: [fswatch](http://stackoverflow.com/a/13807906/151312)), but be careful if `<dirpath>` has thousands of files it will spike your CPU usage to 100%

View File

@ -243,7 +243,7 @@ function run() {
var argv = minimist(process.argv.slice(2)); var argv = minimist(process.argv.slice(2));
var port = parseInt(argv.p || argv.port || argv._[0], 10) || httpsPort; var port = parseInt(argv.p || argv.port || argv._[0], 10) || httpsPort;
var livereload = argv.livereload; 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 content = argv.c;
var letsencryptHost = argv['letsencrypt-certs']; var letsencryptHost = argv['letsencrypt-certs'];
@ -356,13 +356,15 @@ function run() {
return { return {
name: servername name: servername
// there should always be a path // 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 // TODO use arrays in all things
opts._old_server_name = opts.sites[0].name; opts._old_server_name = opts.sites[0].name;
opts.pubdir = defaultWebRoot; opts.pubdir = defaultWebRoot.replace(/(:hostname|:servername).*/, '');
if (argv.p || argv.port || argv._[0]) { if (argv.p || argv.port || argv._[0]) {
opts.manualPort = true; opts.manualPort = true;