From f0ae3da8f186227a04db0fdb84d0b2a478cf2496 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 17 Feb 2017 21:22:38 +0000 Subject: [PATCH] Specify port in cli --- src/cli.ts | 2 ++ src/index.ts | 8 +++++--- src/types/index.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 23b51e0..c5777fd 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,6 +15,7 @@ Usage: Options: -h --help Show this screen. --version Show version. + -p --port= Port to listen on. -b --basic-auth= Enable basic-auth. -i --ips= Allowed IP addresses. -l --list-dir List Directory. @@ -27,6 +28,7 @@ export default function getArgs() : Options { help: true }); return { + port: rawArgs['--port'] || process.env.PORT || 5000, allowed_ips: rawArgs['--ips'] ? rawArgs['--ips'].split(',') : [], basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [], dirList: rawArgs['--list-dir'], diff --git a/src/index.ts b/src/index.ts index 6d40342..c1a3336 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,11 @@ import { docopt } from 'docopt'; import createServer from './server'; import getArgs from './cli'; -console.log("Starting Server...") -const app = createServer(getArgs()); +console.log("Starting Server..."); -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); }); diff --git a/src/types/index.ts b/src/types/index.ts index 30819a0..884dcc1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,6 @@ export interface Options { + port: number; allowed_ips: string[]; basicAuth: string[]; dirList: boolean;