Added next.js logging

This commit is contained in:
MrFry 2020-03-15 13:29:23 +01:00
parent 18aba3c756
commit 9da1cc3a34
3 changed files with 23 additions and 12 deletions

View file

@ -2,7 +2,8 @@
"qmining": { "qmining": {
"path": "./modules/qmining/qmining.js", "path": "./modules/qmining/qmining.js",
"name": "qmining", "name": "qmining",
"urls": [ "qmining.frylabs.net", "localhost" ] "urls": [ "qmining.frylabs.net", "localhost" ],
"isNextJs": true
}, },
"api": { "api": {
"path": "./modules/api/api.js", "path": "./modules/api/api.js",

View file

@ -18,8 +18,6 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
let url = '' // http(s)//asd.basd
const express = require('express') const express = require('express')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const busboy = require('connect-busboy') const busboy = require('connect-busboy')
@ -64,8 +62,5 @@ app.post('*', function (req, res) {
}) })
exports.app = app exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Qmining module started', logger.GetColor('yellow')) logger.Log('Qmining module started', logger.GetColor('yellow'))

View file

@ -67,13 +67,28 @@ app.use(cors())
app.use(function (req, res, next) { app.use(function (req, res, next) {
res.on('finish', function () { res.on('finish', function () {
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress const isNextJs = Object.keys(modules).some((key) => {
logger.LogReq(req, true, res.statusCode) const x = modules[key]
let toLog = loggableKeywords.some((x) => { const match = x.urls.some((url) => {
return req.url.includes(x) return url.includes(req.hostname)
})
if (match) {
return x.isNextJs
}
}) })
if (toLog) { logger.LogReq(req) } if (isNextJs) {
if (res.statusCode !== 404) { logger.LogStat(req.url, ip) } 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) }
}
}) })
next() next()
}) })