UNPKG

@aikidosec/firewall

Version:

Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.

22 lines (21 loc) 740 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRateLimitedEndpoint = getRateLimitedEndpoint; function getRateLimitedEndpoint(context, config) { const matches = config .getEndpoints(context) .filter((m) => m.rateLimiting && m.rateLimiting.enabled); if (matches.length === 0) { return undefined; } const exact = matches.find((m) => m.route === context.route); if (exact) { return exact; } matches.sort((a, b) => { const aRate = a.rateLimiting.maxRequests / a.rateLimiting.windowSizeInMS; const bRate = b.rateLimiting.maxRequests / b.rateLimiting.windowSizeInMS; return aRate - bRate; }); return matches[0]; }