diff --git a/package.json b/package.json index fc78af2..caf25db 100644 --- a/package.json +++ b/package.json @@ -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 ", "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", diff --git a/server.js b/server.js index a3fefa8..04f11cc 100644 --- a/server.js +++ b/server.js @@ -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;