diff --git a/package.json b/package.json index 672322e..1278236 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "express-winston": "=2.2.0", "helmet": "=3.4.0", "opbeat": "=4.11.0", + "open": "=0.0.5", "serve-index": "=1.8.0", "winston": "=2.3.1" }, diff --git a/src/cli.ts b/src/cli.ts index c5777fd..dc0f91c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -19,7 +19,8 @@ Options: -b --basic-auth= Enable basic-auth. -i --ips= Allowed IP addresses. -l --list-dir List Directory. - -o --opbeat Enable Opbeat. + --opbeat Enable Opbeat. + -o --open Open in browser after start. `; export default function getArgs() : Options { @@ -33,6 +34,7 @@ export default function getArgs() : Options { basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [], dirList: rawArgs['--list-dir'], serveDir: rawArgs[''], - opbeat: rawArgs['--opbeat'] + opbeat: rawArgs['--opbeat'], + open: rawArgs['--open'] }; } diff --git a/src/index.ts b/src/index.ts index c1a3336..3c18f8f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { docopt } from 'docopt'; import createServer from './server'; import getArgs from './cli'; +import * as open from 'open'; console.log("Starting Server..."); @@ -8,5 +9,10 @@ const ARGS = getArgs(); const app = createServer(ARGS); const server = app.listen(ARGS.port, function () { - console.log("Server started on port " + server.address().port); + const port = server.address().port; + console.log("Server started on port " + port); + if (ARGS.open) { + open('http://0.0.0.0:' + port); + } }); + diff --git a/src/types/fakes.d.ts b/src/types/fakes.d.ts index 2513eb8..12ce20f 100644 --- a/src/types/fakes.d.ts +++ b/src/types/fakes.d.ts @@ -7,3 +7,4 @@ declare module 'winston'; // doesnt like console transport declare module 'express-winston'; declare module 'opbeat'; declare module 'docopt'; +declare module 'open'; diff --git a/src/types/index.ts b/src/types/index.ts index 884dcc1..d096ad6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,4 +6,5 @@ export interface Options { dirList: boolean; serveDir: string; opbeat: boolean; + open: boolean; }