Prevent DOS and DDOS attack with sailjs app
I'm using sails js in developing a node js application and I want to apply some prevention for DOS and DDOS attack, I see "express-rate-limit" and "express-limiter" packages, In express it is easy to implement using
app.use(limiter({ some parameters }))
but how to implement using sailsjs app?
Solution 1:
Use rate-limiter-flexible, which is not bound to any framework.
Here is basic example:
const opts = {
points: 6, // 6 points
duration: 1, // Per second
};
const rateLimiter = new RateLimiterMemory(opts);
rateLimiter.consume(remoteAddress, 2) // consume 2 points
.then((rateLimiterRes) => {
// 2 points consumed
})
.catch((rateLimiterRes) => {
// Not enough points to consume
});
There are a lot more examples on a package Wiki.