This commit is contained in:
Jake Howard 2017-02-17 09:24:29 +00:00
parent ddc7c41910
commit fcbe06feb3
5 changed files with 50 additions and 5 deletions

View file

@ -2,12 +2,12 @@
"name": "tstatic",
"version": "1.0.0",
"description": "Container to host simple static applications using a node server, so files can be deployed using rsync",
"main": "node ./dist/server.js",
"main": "node ./dist/index.js",
"bin": {
"tstatic": "node ./dist/server.js"
"tstatic": "node ./dist/index.js"
},
"scripts": {
"start": "node ./dist/server.js site/",
"start": "node ./dist/index.js",
"postinstall": "typings install",
"build": "tsc",
"test": "npm run build && nsp check"
@ -28,6 +28,7 @@
"basic-auth": "=1.1.0",
"compression": "=1.6.2",
"connect-static-file": "=1.1.2",
"docopt": "=0.6.2",
"express": "=4.14.1",
"express-basic-auth": "=0.3.2",
"express-ip-access-control": "=1.0.5",

15
src/cli.txt Normal file
View file

@ -0,0 +1,15 @@
tstatic.
Usage:
tstatic <dir> [options]
tstatic -h | --help
tstatic --version
Options:
-h --help Show this screen.
--version Show version.
-b <auth> --basic-auth=<auth> Enable basic-auth.
-i <ips> --ips=<ips> Allowed IP addresses.
-l --list-dir List Directory.
-o --opbeat Enable Opbeat.

28
src/index.ts Normal file
View file

@ -0,0 +1,28 @@
import { docopt } from 'docopt';
import { readFileSync } from 'fs';
import { join } from 'path';
import { Options } from './types';
import createServer from './server';
const ARG_DATA = readFileSync(join(__dirname, '..', 'src', 'cli.txt')).toString();
function getArgs() : Options {
const rawArgs = docopt(ARG_DATA, {
version: require('../package.json').version,
help: true
});
return {
allowed_ips: rawArgs['--ips'] ? rawArgs['--ips'].split(',') : [],
basicAuth: rawArgs['--basic-auth'] || '',
dirList: rawArgs['--list-dir'],
serveDir: rawArgs['<dir>'],
opbeat: rawArgs['--opbeat']
}
}
const app = createServer(getArgs());
const server = app.listen(5000, function () {
console.log("Server started on port " + server.address().port);
});

View file

@ -1,4 +1,4 @@
import express from 'express';
import express, { Application } from 'express';
import AccessControl from 'express-ip-access-control';
import compression from 'compression';
@ -12,7 +12,7 @@ import handle404 from './middleware/404';
import { Options } from './types';
export default function createServer(opts : Options) {
export default function createServer(opts : Options) : Application {
const app = express();
const opbeatHandle = opbeat.start({
active: opts.opbeat

View file

@ -6,3 +6,4 @@ declare module 'express-basic-auth';
declare module 'winston'; // doesnt like console transport
declare module 'express-winston';
declare module 'opbeat';
declare module 'docopt';