Convert to CLI

This commit is contained in:
Jake Howard 2017-01-09 20:34:16 +00:00
parent f2fe3a301b
commit 6955a2af14
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 30 additions and 34 deletions

View file

@ -1,8 +1,11 @@
{
"name": "host-container",
"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": "server.js",
"bin": {
"tstatic": "./server.js"
}
"scripts": {
"test": "npm run mocha && npm run lint && nsp check",
"lint": "eslint server.js tests/**.js",
@ -10,17 +13,17 @@
"mocha": "NODE_ENV=test mocha tests/**.test.js"
},
"engines": {
"node": "5.11.1"
"node": "6.9.4"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RealOrangeOne/host-container.git"
"url": "git+https://github.com/RealOrangeOne/tstatic.git"
},
"author": "Jake Howard <git@theorangeone.net>",
"bugs": {
"url": "https://github.com/RealOrangeOne/host-container/issues"
"url": "https://github.com/RealOrangeOne/tstatic/issues"
},
"homepage": "https://github.com/RealOrangeOne/host-container#readme",
"homepage": "https://github.com/RealOrangeOne/tstatic#readme",
"dependencies": {
"compression": "=1.6.2",
"connect-static-file": "=1.1.2",

View file

@ -6,38 +6,29 @@ const path = require('path');
const winston = require('winston');
const expressWinston = require('express-winston');
const IN_TEST = process.env.NODE_ENV === 'true';
const PORT = process.env.PORT || 5000;
const SERVE_DIR = path.join(__dirname, '/site');
const SERVE_DIR = process.argv[process.argv.length - 1] || 'site/'
const PAGE_404 = path.join(SERVE_DIR, '.404.html');
const EXPRESS_CONFIG = {
dotfiles: 'ignore',
index: false,
redirect: true
};
const LOGGER_MESSAGE = '{{ req.url }}'
.concat('status:{{ res.statusCode }} ')
.concat('useragent:{{ req.headers["user-agent"] }} ')
.concat('time:{{ res.responseTime }}ms');
const app = express();
app.use(compression({ level: 9 }));
app.use(helmet());
if (IN_TEST) {
console.log('Enabling Logging...');
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
colorize: true
})
],
meta: false,
msg: LOGGER_MESSAGE,
colorize: true,
statusLevels: true
}));
}
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
colorize: true
})
],
meta: false,
msg: '{{ req.url }} '
.concat('status:{{ res.statusCode }} ')
.concat('useragent:{{ req.headers["user-agent"] }} ')
.concat('time:{{ res.responseTime }}ms'),
colorize: true,
statusLevels: true
}));
app.use(function (request, response, next) {
if (request.url.endsWith('/')) {
@ -46,7 +37,11 @@ app.use(function (request, response, next) {
next();
});
app.use(express.static(SERVE_DIR, EXPRESS_CONFIG));
app.use(express.static(SERVE_DIR, {
dotfiles: 'ignore',
index: false,
redirect: true
}));
app.use(function (request, response, next) {
response.statusCode = 404;
@ -55,9 +50,7 @@ app.use(function (request, response, next) {
const server = app.listen(PORT, function () {
if (IN_TEST) {
console.log('Server started on port ' + server.address().port);
}
console.log('Server started on port ' + server.address().port);
});
module.exports = server;