mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
prettier 4 tabwidth
This commit is contained in:
parent
00ec614f1d
commit
96b413a365
42 changed files with 7034 additions and 6905 deletions
|
@ -23,68 +23,70 @@ import type { Response, NextFunction } from 'express'
|
|||
import type { Request } from '../types/basicTypes'
|
||||
|
||||
interface Options {
|
||||
loggableKeywords: Array<string>
|
||||
loggableModules: Array<string>
|
||||
exceptions: Array<string>
|
||||
excludeFromStats: Array<string>
|
||||
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.exceptions || []
|
||||
const excludeFromStats = options.excludeFromStats || []
|
||||
const loggableKeywords = options ? options.loggableKeywords : undefined
|
||||
const loggableModules = options ? options.loggableModules : undefined
|
||||
const exceptions = options.exceptions || []
|
||||
const excludeFromStats = options.excludeFromStats || []
|
||||
|
||||
return function (req: Request, res: Response, next: NextFunction) {
|
||||
res.on('finish', function () {
|
||||
// TODO: test this
|
||||
const isException = exceptions.some((ex) => {
|
||||
return req.url.includes(ex)
|
||||
})
|
||||
return function (req: Request, res: Response, next: NextFunction) {
|
||||
res.on('finish', function () {
|
||||
// TODO: test this
|
||||
const isException = exceptions.some((ex) => {
|
||||
return req.url.includes(ex)
|
||||
})
|
||||
|
||||
if (isException) {
|
||||
return
|
||||
}
|
||||
if (isException) {
|
||||
return
|
||||
}
|
||||
|
||||
let hostname = 'NOHOST'
|
||||
if (req.hostname) {
|
||||
hostname = req.hostname.replace('www.', '').split('.')[0]
|
||||
} else {
|
||||
logger.Log('Hostname is undefined!', logger.GetColor('redbg'))
|
||||
console.log(req.body)
|
||||
console.log(req.query)
|
||||
console.log(req.headers)
|
||||
}
|
||||
let hostname = 'NOHOST'
|
||||
if (req.hostname) {
|
||||
hostname = req.hostname.replace('www.', '').split('.')[0]
|
||||
} else {
|
||||
logger.Log('Hostname is undefined!', logger.GetColor('redbg'))
|
||||
console.log(req.body)
|
||||
console.log(req.query)
|
||||
console.log(req.headers)
|
||||
}
|
||||
|
||||
const hasLoggableKeyword =
|
||||
loggableKeywords &&
|
||||
loggableKeywords.some((keyword) => {
|
||||
return req.url.includes(keyword)
|
||||
const hasLoggableKeyword =
|
||||
loggableKeywords &&
|
||||
loggableKeywords.some((keyword) => {
|
||||
return req.url.includes(keyword)
|
||||
})
|
||||
const hasLoggableModule =
|
||||
loggableModules &&
|
||||
loggableModules.some((keyword) => {
|
||||
return hostname.includes(keyword)
|
||||
})
|
||||
const toLog = hasLoggableModule || hasLoggableKeyword
|
||||
|
||||
logger.LogReq(req, true, res.statusCode)
|
||||
if (toLog) {
|
||||
logger.LogReq(req)
|
||||
}
|
||||
|
||||
const shouldLogStat = !excludeFromStats.some((ex) => {
|
||||
return req.url.includes(ex)
|
||||
})
|
||||
|
||||
if (res.statusCode !== 404 && shouldLogStat) {
|
||||
logger.LogStat(
|
||||
req.url,
|
||||
hostname,
|
||||
req.session && req.session.user
|
||||
? req.session.user.id
|
||||
: 'NOUSER'
|
||||
)
|
||||
}
|
||||
})
|
||||
const hasLoggableModule =
|
||||
loggableModules &&
|
||||
loggableModules.some((keyword) => {
|
||||
return hostname.includes(keyword)
|
||||
})
|
||||
const toLog = hasLoggableModule || hasLoggableKeyword
|
||||
|
||||
logger.LogReq(req, true, res.statusCode)
|
||||
if (toLog) {
|
||||
logger.LogReq(req)
|
||||
}
|
||||
|
||||
const shouldLogStat = !excludeFromStats.some((ex) => {
|
||||
return req.url.includes(ex)
|
||||
})
|
||||
|
||||
if (res.statusCode !== 404 && shouldLogStat) {
|
||||
logger.LogStat(
|
||||
req.url,
|
||||
hostname,
|
||||
req.session && req.session.user ? req.session.user.id : 'NOUSER'
|
||||
)
|
||||
}
|
||||
})
|
||||
next()
|
||||
}
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue