Excluding things from request stats, script registering endpoint

This commit is contained in:
mrfry 2021-01-11 09:28:18 +01:00
parent b53fd84bf2
commit f19226a74e
5 changed files with 87 additions and 9 deletions

View file

@ -4,12 +4,14 @@ interface Options {
loggableKeywords: Array<string>
loggableModules: Array<string>
exceptions: Array<string>
excludeFromStats: Array<string>
}
export default function(options: Options): any {
const loggableKeywords = options ? options.loggableKeywords : undefined
const loggableModules = options ? options.loggableModules : undefined
const exceptions = options ? options.exceptions : []
const exceptions = options.exceptions || []
const excludeFromStats = options.excludeFromStats || []
return function(req, res, next) {
res.on('finish', function() {
@ -49,7 +51,12 @@ export default function(options: Options): any {
if (toLog) {
logger.LogReq(req)
}
if (res.statusCode !== 404) {
const shouldLogStat = !excludeFromStats.some((ex) => {
return req.url.includes(ex)
})
if (res.statusCode !== 404 && shouldLogStat) {
logger.LogStat(
req.url,
ip,