[develop | DONE | ADDED ] Cache: add access logs

This commit is contained in:
argirok 2024-07-15 11:37:16 +03:00
parent d484f4afda
commit 706fe7cd07
2 changed files with 20 additions and 1 deletions

View File

@ -11,6 +11,7 @@ const PropertiesReader = require('properties-reader');
const properties = PropertiesReader('./properties.file');
const environment = properties.get("environment");
const preloadRequests = properties.get("preloadRequests").split(',');;
var accesslog = require('access-log');
const cacheMaxSize = 1000;
let cors = require('cors');
@ -84,10 +85,11 @@ let cache = () => {
}
};
accesslogCustomFormat(req, res);
next();
}
} else {
accesslogCustomFormat(req, res);
next();
}
};
@ -117,15 +119,18 @@ app.get('/clear', (req, res) => {
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
res.header("Content-Type", "application/json");
accesslogCustomFormat(req, res);
res.status(200).send(getResponse(200, message));
});
app.get('/metrics', (req, res) => {
res.set('Content-Type', register.contentType);
accesslogCustomFormat(req, res);
res.end(register.metrics());
});
app.get('/info', (req, res) => {
accesslogCustomFormat(req, res);
res.status(200).send(getResponse(200, {size:lruCache.size, keys: Array.from(lruCache.keys())}));
});
@ -210,3 +215,16 @@ function resetAtMidnight() {
resetAtMidnight(); // Then, reset again next midnight.
}, msToMidnight);
}
function accesslogCustomFormat(req, res){
accesslog(req, res,
/*{
userID: function (req) { return req.user; },
format : 'url=":url" method=":method" statusCode=":statusCode" delta=":delta" ip=":ip"'
}*/);
// url="/clear" method="GET" statusCode="200" delta="2" ip="::ffff:195.134.66.178"
// ::ffff:195.134.66.178 - - [15/Jul/2024:11:24:35 +0300] "GET /clear HTTP/1.1" 200 59 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0"
}

View File

@ -10,6 +10,7 @@
"prepare-prod": " npm run prepare-dist; cp production-properties.file ./dist/properties.file"
},
"dependencies": {
"access-log": "^0.4.1",
"axios": "^1.6.7",
"compression": "^1.7.4",
"cors": "^2.8.5",