mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
feat: console log incoming requests on dev mode
This commit is contained in:
parent
bf077f4aa3
commit
ffe6d6ed88
24
controllers/middlewares/DebugLogging.js
Normal file
24
controllers/middlewares/DebugLogging.js
Normal file
@ -0,0 +1,24 @@
|
||||
const logger = require('./../../logger')
|
||||
|
||||
class RequestLogging {
|
||||
constructor () {
|
||||
logger.log('Initiated RequestLogging middleware.')
|
||||
}
|
||||
|
||||
#middleware (req, res, next) {
|
||||
req.locals.debug = {
|
||||
ip: req.ip,
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
path_parameters: req.path_parameters
|
||||
}
|
||||
logger.log(`Incoming from ${req.locals.debug.ip} -> ${req.locals.debug.method} ${req.locals.debug.path}`)
|
||||
return next()
|
||||
}
|
||||
|
||||
get middleware () {
|
||||
return this.#middleware.bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RequestLogging
|
@ -55,6 +55,7 @@ paths.initSync()
|
||||
const utils = require('./controllers/utilsController')
|
||||
|
||||
// Middlewares
|
||||
const DebugLogging = require('./controllers/middlewares/DebugLogging')
|
||||
const ExpressCompat = require('./controllers/middlewares/ExpressCompat')
|
||||
const NunjucksRenderer = require('./controllers/middlewares/NunjucksRenderer')
|
||||
const RateLimiter = require('./controllers/middlewares/RateLimiter')
|
||||
@ -71,6 +72,12 @@ const file = require('./routes/file')
|
||||
const nojs = require('./routes/nojs')
|
||||
const player = require('./routes/player')
|
||||
|
||||
// Incoming requests logging (development mode)
|
||||
if (utils.devmode) {
|
||||
const DebugLoggingInstance = new DebugLogging()
|
||||
safe.use(DebugLoggingInstance.middleware)
|
||||
}
|
||||
|
||||
// Express-compat
|
||||
const expressCompatInstance = new ExpressCompat()
|
||||
safe.use(expressCompatInstance.middleware)
|
||||
|
Loading…
Reference in New Issue
Block a user