Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: print additional debug info if debug set to true in get middleware #35

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading