README
antiflood
Really efficient Antiflood for you API
Installation
$ npm i antiflood
Initialization
const Antiflood = require('antiflood'); const test = new Antiflood( (number)MAX_REQUESTS_COUNT, (number)FLOOD_RESET_TIME );
# Declare a new request
(constants and variables names are based on the "Initialization" section)test.feed(TOKEN)
Description of API
The constructor, accepts 2 numbers:- MAX_REQUESTS_COUNT: How many requests can a user make in FLOOD_RESET_TIME?
- FLOOD_RESET_TIME: Time in seconds after user can make a new cycle of requests
How does tokens work?
The token is that identifying object that allows the flood to group users based on requests, so you can create various Antifloods based on the TOKEN object passed by parameter. Example: User A: makes 3 requests within 10 seconds, and is blocked User B (with another token): at the same time as User A makes 2 requests in 10 seconds, he is not blocked because he has another token.const email_verification = new Antiflood(2, 30); // 2 request every 30 seconds email_verification.feed({user: 1}); // allowed email_verification.feed({user: 2}); // allowed email_verification.feed({user: 1}); // allowed email_verification.feed({user: 1}); // denied email_verification.feed({user: 2}); // allowed