Rate Limit

  • To prevent brute force attacks, the framework comes with a rate limit function, which is disabled by default. You can configure it globally in ndsk.config.js,
module.exports = (isPro)=>{
    return {
        server:{
            plugins:{
                ratelimit:{
                    userLimit:10,                         //The total number of requests that a user can make in each time period
                    userCacheExp:1000                     //Cache expiration time
                }
            }
        }  
    }
}
  • The above configuration means that each user is limited to 10 requests per second (all routes)

  • You can also configure it separately in the route

export const options = {
    plugins:{
        ratelimit:{
            userPathLimit:1,
            userPathCacheExp:1000,
        }
    }
}
export default ()=>{
    return 'ratelimit'
}
  • The above means: limit the current route to only one request per user per second

  • You can also configure it like this

export const options = {
    plugins:{
        ratelimit:{
            pathLimit:1,
            pathCacheExp:1000,
        }
    }
}
export default ()=>{
    return 'ratelimit'
}
  • The above means: limit the current route to only one request every 10 seconds (all users)

Provide the following configuration parameters

  • enabled Set it to false in the route configuration to bypass all rate limits for this route

  • userLimit The total number of requests that can be made by each user per period, set to false to disable limiting the number of requests per user

  • userCacheExp The cache period used to store user rate limit information ms

  • pathLimit The total number of requests that can be made on a given path per period. Set to false to disable limiting the number of requests per path.

  • pathCacheExp The name of the cache segment used to store path rate limit information ms

  • userPathLimit The total number of requests that can be made on a given path per period per user. Set to false to disable limiting the number of requests per user per path

  • userPathCacheExp is used to store the cache period ms of userPath rate limit information

  • ignorePathParams if false, the limit will be applied to the route (/route/{param}: a single cache entry) instead of 2 different caches for the path /route/1 or /route/2

Next

Scheduled task