Access log file option

This commit is contained in:
Klemek
2019-06-22 00:07:54 +02:00
parent 4171f565f8
commit 3cfa2bfc71
4 changed files with 96 additions and 63 deletions
+18
View File
@@ -3,6 +3,8 @@ const app = express();
const fs = require('fs');
const path = require('path');
app.enable('trust proxy');
//rss
const Rss = require('rss');
@@ -94,6 +96,22 @@ module.exports = (config) => {
});
};
//log request at result end
app.use((req, res, next) => {
if (config['access_log']) {
const end = res.end;
res.end = (chunk, encoding) => {
fs.appendFile(config['access_log'],
res.statusCode + ' ' + req.method + ' ' + req.url + ' ' + new Date().toUTCString() + ' ' + (req.ips.join(' ') || req.ip) + '\n',
{encoding: 'UTF-8'}, () => {
res.end = end;
res.end(chunk, encoding);
});
};
}
next();
});
// home endpoint : send the correct index page or error if not existing
app.get('/', (req, res) => {
const homePath = path.join(config['data_dir'], config['home']['index']);