Skip to content

Commit

Permalink
docs(readme): spelling and grammar fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Frazer Smith <[email protected]>
  • Loading branch information
Fdawgs authored Jan 10, 2025
1 parent 65545aa commit ed4cb39
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).<br> **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`
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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: {
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit ed4cb39

Please sign in to comment.