From 83672f17007805f695071fa8723b6c84612b0b0c Mon Sep 17 00:00:00 2001 From: Renzo Beux <renzobeux@gmail.com> Date: Sat, 30 Oct 2021 17:52:58 -0300 Subject: [PATCH] log on request --- src/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/index.ts b/src/index.ts index a299502..e8e3317 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,28 @@ app.use(express.raw({ limit: '50mb', })); +app.use((req, res, next) => { + const reqToLog = { + body: { ...req.body }, + hostname: req.hostname, + ip: req.ip, + method: req.method, + params: { ...req.params }, + path: req.path, + protocol: req.protocol, + query: { ...req.query }, + secure: req.secure, + }; + + // before logging the request, we have to hide sensitive information + if (typeof reqToLog.body.password !== 'undefined') { + reqToLog.body.password = '__HIDDEN__'; + } + + logger.info('Request received', { request: reqToLog }); + next(); +}); + app.use(Routes); app.use((error: Error, request: Request, response: Response, next: NextFunction) => { -- GitLab