Access log file option
This commit is contained in:
+18
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user