From 796d519c3177b280cd0a306233b6d1a5b07eb8ee Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 18 Aug 2021 18:50:47 +0200 Subject: [PATCH] Added request logging --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index 6f8b8f7..55917e2 100644 --- a/index.js +++ b/index.js @@ -57,8 +57,18 @@ async function asyncMain() const app = express(); + + const logMiddleware = (req, res, next) => + { + // TODO merge with api.js' version + const ip = req.headers['x-forwarded-for'] || req.ip; + logger.verbose(`[${ip}] ${req.path} (body = ${JSON.stringify(req.body)})`); + next() + } + app.use(express.json()); app.use(express.urlencoded({ extended: false })); + app.use(logMiddleware); app.use('/api', container.ApiRoutes.createRouter(express)); app.use('/', express.static('frontend/dist'));