mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Next js logging
This commit is contained in:
parent
0e643f59c0
commit
355c0e353e
1 changed files with 9 additions and 21 deletions
30
server.js
30
server.js
|
@ -67,28 +67,16 @@ app.use(cors())
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.on('finish', function () {
|
res.on('finish', function () {
|
||||||
const isNextJs = Object.keys(modules).some((key) => {
|
if (req.url.includes('_next/static')) {
|
||||||
const x = modules[key]
|
return
|
||||||
const match = x.urls.some((url) => {
|
|
||||||
return url.includes(req.hostname)
|
|
||||||
})
|
|
||||||
if (match) {
|
|
||||||
return x.isNextJs
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (isNextJs) {
|
|
||||||
if (req.url === '/') {
|
|
||||||
logger.LogReq(req, true, res.statusCode)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
|
||||||
logger.LogReq(req, true, res.statusCode)
|
|
||||||
let toLog = loggableKeywords.some((x) => {
|
|
||||||
return req.url.includes(x)
|
|
||||||
})
|
|
||||||
if (toLog) { logger.LogReq(req) }
|
|
||||||
if (res.statusCode !== 404) { logger.LogStat(req.url, ip) }
|
|
||||||
}
|
}
|
||||||
|
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||||
|
logger.LogReq(req, true, res.statusCode)
|
||||||
|
let toLog = loggableKeywords.some((x) => {
|
||||||
|
return req.url.includes(x)
|
||||||
|
})
|
||||||
|
if (toLog) { logger.LogReq(req) }
|
||||||
|
if (res.statusCode !== 404) { logger.LogStat(req.url, ip) }
|
||||||
})
|
})
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue