From 9da1cc3a3471e76d14c6e248bb49e975e556a92e Mon Sep 17 00:00:00 2001 From: MrFry Date: Sun, 15 Mar 2020 13:29:23 +0100 Subject: [PATCH] Added next.js logging --- modules.json | 3 ++- modules/qmining/qmining.js | 5 ----- server.js | 27 +++++++++++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/modules.json b/modules.json index 6afa8c1..9750d7a 100644 --- a/modules.json +++ b/modules.json @@ -2,7 +2,8 @@ "qmining": { "path": "./modules/qmining/qmining.js", "name": "qmining", - "urls": [ "qmining.frylabs.net", "localhost" ] + "urls": [ "qmining.frylabs.net", "localhost" ], + "isNextJs": true }, "api": { "path": "./modules/api/api.js", diff --git a/modules/qmining/qmining.js b/modules/qmining/qmining.js index d6d7b2a..27ad7d5 100644 --- a/modules/qmining/qmining.js +++ b/modules/qmining/qmining.js @@ -18,8 +18,6 @@ ------------------------------------------------------------------------- */ -let url = '' // http(s)//asd.basd - const express = require('express') const bodyParser = require('body-parser') const busboy = require('connect-busboy') @@ -64,8 +62,5 @@ app.post('*', function (req, res) { }) exports.app = app -exports.setup = (x) => { - url = x.url -} logger.Log('Qmining module started', logger.GetColor('yellow')) diff --git a/server.js b/server.js index 8af78f0..3b9c138 100755 --- a/server.js +++ b/server.js @@ -67,13 +67,28 @@ app.use(cors()) app.use(function (req, res, next) { res.on('finish', function () { - 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) + const isNextJs = Object.keys(modules).some((key) => { + const x = modules[key] + const match = x.urls.some((url) => { + return url.includes(req.hostname) + }) + if (match) { + return x.isNextJs + } }) - if (toLog) { logger.LogReq(req) } - if (res.statusCode !== 404) { logger.LogStat(req.url, ip) } + 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) } + } }) next() })