mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Added next.js logging
This commit is contained in:
		@@ -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",
 | 
			
		||||
 
 | 
			
		||||
@@ -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'))
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								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()
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user