Pure Node.js simple rate limiting server to prevent bruteforce attacks
This project is maintained by yonjah
Client for ralphi pure Node.js rate limiting server
Ralphi
is a simple rate limiting server intended to prevent bruteforce attacks on logins and other sensitive assets.
For more info about Ralphi other components see ralphi
$ npm install -s ralphi-client
const host = 'localhost';
const port = 8910;
const RalphiClient = require('ralphi-client');
const client = new RalphiClient({port, host});
async function handler (req, res) { //in your handler code
const limit = await client.take('login', req.ip);
if (limit.conformant) {
//allow access
return `Request was done. You have ${limit.remaining} more requests until ${new Date(limit.ttl * 1000)}`;
} else {
//reject access
throw new Error(`You have made too many requests. You can send ${limit.size} requests after ${new Date(limit.ttl * 1000)}`);
}
}
Ralphi Client is using a Promise API all methods return Promises
give
is meant to be used to give back a token that wasn’t suppose to be taken (like if login was successful). even after giving a token you can’t be sure next request will be conformant cause other requests may have overdrawn the bucket if you want to manually force bucket to have more tokens you should use reset
true
if record existed and false
if it wasn’t