Add HTTP request logging

Related to #27.
This commit is contained in:
Zalmoxisus
2016-11-09 13:49:24 +02:00
parent ee32bd52a6
commit 9c048e66ef
4 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,7 @@ var path = require('path');
var app = require('express')();
var bodyParser = require('body-parser');
var cors = require('cors');
var morgan = require('morgan');
var createStore = require('./store');
module.exports.run = function(worker) {
@ -9,6 +10,7 @@ module.exports.run = function(worker) {
var scServer = worker.scServer;
var store = createStore(worker.options);
var limit = worker.options.maxRequestBody;
var logHTTPRequests = worker.options.logHTTPRequests;
httpServer.on('request', app);
@ -19,6 +21,11 @@ module.exports.run = function(worker) {
res.render('index', { port: worker.options.port });
});
if (logHTTPRequests) {
if (typeof logHTTPRequests === 'object') app.use(morgan('combined', logHTTPRequests));
else app.use(morgan('combined'));
}
app.use(cors({ methods: 'POST' }));
app.use(bodyParser.json({ limit: limit }));
app.use(bodyParser.urlencoded({ limit: limit, extended: false }));