From dcc04ddb79f9b2999b018df62cb90b361266b4a2 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Thu, 1 Aug 2024 16:43:09 +0100 Subject: [PATCH] feat: print additional debug info if debug set to true in get middleware --- src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 0eef90f..2b4ad80 100644 --- a/src/index.js +++ b/src/index.js @@ -35,7 +35,7 @@ const addCheck = (check) => healthChecks.push(check); const addReadinessCheck = (check) => readinessChecks.push(check); const addMetrics = (m) => { metrics = m; }; -const getMiddleware = () => (req, res, next) => { +const getMiddleware = (debug = false) => (req, res, next) => { const requestingIP = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; @@ -43,8 +43,10 @@ const getMiddleware = () => (req, res, next) => { const ipVersion = net.isIPv6(requestingIP) ? 'ipv6' : 'ipv4'; if (!blocklist.check(requestingIP, ipVersion)) { - // eslint-disable-next-line no-console - console.debug(`Blocking request from ${requestingIP}`); + if (debug) { + // eslint-disable-next-line no-console + console.debug(`Blocking request from ${requestingIP}`); + } return next(); }