Skip to content

Commit

Permalink
feat: print additional debug info if debug set to true in get middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Jafferwaffer committed Aug 2, 2024
1 parent 566c12e commit e77d13a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ 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;

// Only expect private IPs from this range
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();
}
Expand Down

0 comments on commit e77d13a

Please sign in to comment.