Added a .env toggle for enabling/disabling detailed route logging

This commit is contained in:
emad-salah 2020-07-23 16:43:54 +01:00
parent fa63bc7c24
commit 59f44e825a
2 changed files with 25 additions and 24 deletions

View file

@ -272,8 +272,6 @@ module.exports = async (
app.use(async (req, res, next) => { app.use(async (req, res, next) => {
try { try {
logger.info("Route:", req.path)
if (unprotectedRoutes[req.method][req.path]) { if (unprotectedRoutes[req.method][req.path]) {
next(); next();
return; return;

View file

@ -195,31 +195,34 @@ const server = program => {
}) })
app.use((req, res, next) => { app.use((req, res, next) => {
if (sensitiveRoutes[req.method][req.path]) { if (process.env.ROUTE_LOGGING === 'true') {
logger.info( if (sensitiveRoutes[req.method][req.path]) {
JSON.stringify({ logger.info(
time: new Date(), JSON.stringify({
ip: req.ip, time: new Date(),
method: req.method, ip: req.ip,
path: req.path, method: req.method,
sessionId: req.sessionId path: req.path,
}) sessionId: req.sessionId
) })
} else { )
logger.info( } else {
JSON.stringify({ logger.info(
time: new Date(), JSON.stringify({
ip: req.ip, time: new Date(),
method: req.method, ip: req.ip,
path: req.path, method: req.method,
body: req.body, path: req.path,
query: req.query, body: req.body,
sessionId: req.sessionId query: req.query,
}) sessionId: req.sessionId
) })
)
}
} }
next() next()
}) })
app.use( app.use(
session({ session({
secret: defaults.sessionSecret, secret: defaults.sessionSecret,