Skip to content

Commit 7be5407

Browse files
author
George Thomas
authored
feat: print additional debug info if debug set to true in get middleware (#35)
1 parent 566c12e commit 7be5407

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ const addCheck = (check) => healthChecks.push(check);
3535
const addReadinessCheck = (check) => readinessChecks.push(check);
3636
const addMetrics = (m) => { metrics = m; };
3737

38-
const getMiddleware = () => (req, res, next) => {
38+
const getMiddleware = ({ debug = false } = {}) => (req, res, next) => {
3939
const requestingIP = req.ip || req.connection.remoteAddress
4040
|| req.socket.remoteAddress || req.connection.socket.remoteAddress;
4141

4242
// Only expect private IPs from this range
4343
const ipVersion = net.isIPv6(requestingIP) ? 'ipv6' : 'ipv4';
4444

4545
if (!blocklist.check(requestingIP, ipVersion)) {
46-
// eslint-disable-next-line no-console
47-
console.debug(`Blocking request from ${requestingIP}`);
46+
if (debug) {
47+
// eslint-disable-next-line no-console
48+
console.debug(`Blocking request from ${requestingIP}`);
49+
}
4850

4951
return next();
5052
}

0 commit comments

Comments
 (0)