From ed4cb39b48b2b985fbbed98e23f2639f533e5c7b Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 10 Jan 2025 18:32:39 +0000 Subject: [PATCH] docs(readme): spelling and grammar fixes Signed-off-by: Frazer Smith --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f281a57..3779a75 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ await fastify.register(import('@fastify/rate-limit'), { - `max`: maximum number of requests a single client can perform inside a timeWindow. It can be an async function with the signature `async (request, key) => {}` where `request` is the Fastify request object and `key` is the value generated by the `keyGenerator`. The function **must** return a number. - `ban`: maximum number of 429 responses to return to a client before returning 403 responses. When the ban limit is exceeded, the context argument that is passed to `errorResponseBuilder` will have its `ban` property set to `true`. **Note:** `0` can also be passed to directly return 403 responses when a client exceeds the `max` limit. - `timeWindow:` the duration of the time window. It can be expressed in milliseconds, as a string (in the [`ms`](https://github.com/zeit/ms) format), or as an async function with the signature `async (request, key) => {}` where `request` is the Fastify request object and `key` is the value generated by the `keyGenerator`. The function **must** return a number. -- `cache`: this plugin internally uses a lru cache to handle the clients, you can change the size of the cache with this option -- `allowList`: array of string of ips to exclude from rate limiting. It can be a sync or async function with the signature `(request, key) => {}` where `request` is the Fastify request object and `key` is the value generated by the `keyGenerator`. If the function return a truthy value, the request will be excluded from the rate limit. +- `cache`: this plugin internally uses an LRU cache to handle the clients, you can change the size of the cache with this option +- `allowList`: array of string of IPs to exclude from rate limiting. It can be a sync or async function with the signature `(request, key) => {}` where `request` is the Fastify request object and `key` is the value generated by the `keyGenerator`. If the function return a truthy value, the request will be excluded from the rate limit. - `redis`: by default, this plugin uses an in-memory store, but if an application runs on multiple servers, an external store will be needed. This plugin requires the use of [`ioredis`](https://github.com/redis/ioredis).
**Note:** the [default settings](https://github.com/redis/ioredis/blob/v4.16.0/API.md#new_Redis_new) of an ioredis instance are not optimal for rate limiting. We recommend customizing the `connectTimeout` and `maxRetriesPerRequest` parameters as shown in the [`example`](https://github.com/fastify/fastify-rate-limit/tree/master/example/example.js). - `nameSpace`: choose which prefix to use in the redis, default is 'fastify-rate-limit-' - `continueExceeding`: Renew user limitation when user sends a request to the server when still limited. This will take priority over `exponentialBackoff` @@ -241,7 +241,7 @@ fastify.addHook('preHandler', async function (request) { Custom `store` example usage: -NOTE: The ```timeWindow``` will always be passed as the numeric value in millseconds into the store's constructor. +NOTE: The ```timeWindow``` will always be passed as the numeric value in milliseconds into the store's constructor. ```js function CustomStore (options) { @@ -309,7 +309,7 @@ await fastify.register(import('@fastify/rate-limit'), { ### Options on the endpoint itself -Rate limiting can be also can be configured at the route level, applying the configuration independently. +Rate limiting can also be configured at the route level, applying the configuration independently. For example the `allowList` if configured: - on plugin registration will affect all endpoints within the encapsulation scope @@ -321,7 +321,7 @@ The endpoint allowlist is set on the endpoint directly with the `{ config : { ra ACL checking is performed based on the value of the key from the `keyGenerator`. -In this example we are checking the IP address, but it could be an allowlist of specific user identifiers (like JWT or tokens): +In this example, we are checking the IP address, but it could be an allowlist of specific user identifiers (like JWT or tokens): ```js import Fastify from 'fastify' @@ -371,7 +371,7 @@ fastify.get('/public/sub-rated-1', { timeWindow: '1 minute', allowList: ['127.0.0.1'], onExceeding: function (request, key) { - console.log('callback on exceededing ... executed before response to client') + console.log('callback on exceeding ... executed before response to client') }, onExceeded: function (request, key) { console.log('callback on exceeded ... to black ip in security group for example, request is give as argument') @@ -382,7 +382,7 @@ fastify.get('/public/sub-rated-1', { reply.send({ hello: 'from sub-rated-1 ... using default max value ... ' }) }) -// gorup routes and add a rate limit +// group routes and add a rate limit fastify.get('/otp/send', { config: { rateLimit: { @@ -410,10 +410,10 @@ fastify.get('/otp/resend', { In the route creation you can override the same settings of the plugin registration plus the following additional options: -- `onExceeding` : callback that will be executed each time a request is made to a route that is rate limited -- `onExceeded` : callback that will be executed when a user reached the maximum number of tries. Can be useful to blacklist clients +- `onExceeding` : callback that will be executed each time a request is made to a route that is rate-limited +- `onExceeded` : callback that will be executed when a user reaches the maximum number of tries. Can be useful to blacklist clients -You may also want to set a global rate limiter and then disable on some routes: +You may also want to set a global rate limiter and then disable it on some routes: ```js import Fastify from 'fastify'