Specify port in cli

This commit is contained in:
Jake Howard 2017-02-17 21:22:38 +00:00
parent b5c8775c81
commit f0ae3da8f1
3 changed files with 8 additions and 3 deletions

View file

@ -15,6 +15,7 @@ Usage:
Options: Options:
-h --help Show this screen. -h --help Show this screen.
--version Show version. --version Show version.
-p <port> --port=<port> Port to listen on.
-b <auth> --basic-auth=<auth> Enable basic-auth. -b <auth> --basic-auth=<auth> Enable basic-auth.
-i <ips> --ips=<ips> Allowed IP addresses. -i <ips> --ips=<ips> Allowed IP addresses.
-l --list-dir List Directory. -l --list-dir List Directory.
@ -27,6 +28,7 @@ export default function getArgs() : Options {
help: true help: true
}); });
return { return {
port: rawArgs['--port'] || process.env.PORT || 5000,
allowed_ips: rawArgs['--ips'] ? rawArgs['--ips'].split(',') : [], allowed_ips: rawArgs['--ips'] ? rawArgs['--ips'].split(',') : [],
basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [], basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [],
dirList: rawArgs['--list-dir'], dirList: rawArgs['--list-dir'],

View file

@ -2,9 +2,11 @@ import { docopt } from 'docopt';
import createServer from './server'; import createServer from './server';
import getArgs from './cli'; import getArgs from './cli';
console.log("Starting Server...") console.log("Starting Server...");
const app = createServer(getArgs());
const server = app.listen(5000, function () { const ARGS = getArgs();
const app = createServer(ARGS);
const server = app.listen(ARGS.port, function () {
console.log("Server started on port " + server.address().port); console.log("Server started on port " + server.address().port);
}); });

View file

@ -1,5 +1,6 @@
export interface Options { export interface Options {
port: number;
allowed_ips: string[]; allowed_ips: string[];
basicAuth: string[]; basicAuth: string[];
dirList: boolean; dirList: boolean;