Open site after server start

This commit is contained in:
Jake Howard 2017-02-17 21:33:32 +00:00
parent f0ae3da8f1
commit 390c1e80cd
5 changed files with 14 additions and 3 deletions

View File

@ -35,6 +35,7 @@
"express-winston": "=2.2.0", "express-winston": "=2.2.0",
"helmet": "=3.4.0", "helmet": "=3.4.0",
"opbeat": "=4.11.0", "opbeat": "=4.11.0",
"open": "=0.0.5",
"serve-index": "=1.8.0", "serve-index": "=1.8.0",
"winston": "=2.3.1" "winston": "=2.3.1"
}, },

View File

@ -19,7 +19,8 @@ Options:
-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.
-o --opbeat Enable Opbeat. --opbeat Enable Opbeat.
-o --open Open in browser after start.
`; `;
export default function getArgs() : Options { export default function getArgs() : Options {
@ -33,6 +34,7 @@ export default function getArgs() : Options {
basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [], basicAuth: rawArgs['--basic-auth'] ? rawArgs['--basic-auth'].split(':') : [],
dirList: rawArgs['--list-dir'], dirList: rawArgs['--list-dir'],
serveDir: rawArgs['<dir>'], serveDir: rawArgs['<dir>'],
opbeat: rawArgs['--opbeat'] opbeat: rawArgs['--opbeat'],
open: rawArgs['--open']
}; };
} }

View File

@ -1,6 +1,7 @@
import { docopt } from 'docopt'; import { docopt } from 'docopt';
import createServer from './server'; import createServer from './server';
import getArgs from './cli'; import getArgs from './cli';
import * as open from 'open';
console.log("Starting Server..."); console.log("Starting Server...");
@ -8,5 +9,10 @@ const ARGS = getArgs();
const app = createServer(ARGS); const app = createServer(ARGS);
const server = app.listen(ARGS.port, function () { 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);
}
}); });

View File

@ -7,3 +7,4 @@ declare module 'winston'; // doesnt like console transport
declare module 'express-winston'; declare module 'express-winston';
declare module 'opbeat'; declare module 'opbeat';
declare module 'docopt'; declare module 'docopt';
declare module 'open';

View File

@ -6,4 +6,5 @@ export interface Options {
dirList: boolean; dirList: boolean;
serveDir: string; serveDir: string;
opbeat: boolean; opbeat: boolean;
open: boolean;
} }