Skip to content

Commit fcb6e2a

Browse files
committed
docs: address pull review comments to match styling
1 parent a8b2631 commit fcb6e2a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

content/security/rate-limiting.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A common technique to protect applications from brute-force attacks is **rate-limiting**. To get started, you'll need to install the `@nestjs/throttler` package.
44

55
```bash
6-
$ npm i --save @nestjs/throttle
6+
$ npm i --save @nestjs/throttler
77
```
88

99
Once the installation is complete, the `ThrottlerModule` can be configured as any other Nest package with `forRoot` or `forRootAsync` methods.
@@ -22,7 +22,7 @@ export class AppModule {}
2222

2323
The above will set the global options for the `ttl`, the time to live, and the `limit`, the maximum number of requests within the ttl, for the routes of your application that are guarded.
2424

25-
Once the module has been imported, you can then choose how you would like to bind the `ThrottlerGuard`. Any kind of binding as mentioned in the [guards](https://docs.nestjs.com/guards) section is fine. If you wanted to bind the guard globally, for example, you could do so but adding this provider to any module
25+
Once the module has been imported, you can then choose how you would like to bind the `ThrottlerGuard`. Any kind of binding as mentioned in the [guards](https://docs.nestjs.com/guards) section is fine. If you wanted to bind the guard globally, for example, you could do so by adding this provider to any module:
2626

2727
```typescript
2828
{
@@ -33,13 +33,13 @@ Once the module has been imported, you can then choose how you would like to bin
3333

3434
#### Customization
3535

36-
There may be a time where you want to bind the guard to a controller or globally, but want to avoid rate limiting one or more of your endpoints. For that, you can use the `@SkipThrottle()` decorator, to negate the throttler for an entire class or a single route. The `@SkipThrottle()` decorator can also take in a boolean for if there is a case where you want to exclude _most_ of a controller, but not every route.
36+
There may be a time where you want to bind the guard to a controller or globally, but want to disable rate limiting for one or more of your endpoints. For that, you can use the `@SkipThrottle()` decorator, to negate the throttler for an entire class or a single route. The `@SkipThrottle()` decorator can also take in a boolean for if there is a case where you want to exclude _most_ of a controller, but not every route.
3737

38-
There is also the `@Throttle()` decorator which can be used to override the `limit` and `ttl` set in the global module, to give tighter or looser security options. This decorator can be used on a class or a function as well. The order for this decorator does matter, as the arguments are in the order of `limit` `ttl`.
38+
There is also the `@Throttle()` decorator which can be used to override the `limit` and `ttl` set in the global module, to give tighter or looser security options. This decorator can be used on a class or a function as well. The order for this decorator does matter, as the arguments are in the order of `limit, ttl`.
3939

4040
#### Websockets
4141

42-
This module _can_ work with websockets, but it requires some class extension. You can extend the `ThrottlerGuard` and override the `handleRequest` method like so:
42+
This module can work with websockets, but it requires some class extension. You can extend the `ThrottlerGuard` and override the `handleRequest` method like so:
4343

4444
```typescript
4545
@Injectable()
@@ -69,7 +69,7 @@ The `ThrottlerGuard` can also be used to work with GraphQL requests. Again, the
6969
```typescript
7070
@Injectable()
7171
export class GqlThrottlerGuard extends ThrottlerGuard {
72-
getRequestResponse(context: ExecutionContext): { req: Record<string, any>, res: Record<string, any> } {
72+
getRequestResponse(context: ExecutionContext) {
7373
const gqlCtx = GqlExecutionContext.create(context);
7474
const ctx = gql.getContext();
7575
return { req, ctx.req, res: ctx.res }
@@ -79,7 +79,7 @@ export class GqlThrottlerGuard extends ThrottlerGuard {
7979

8080
#### Configuration
8181

82-
The following options are valid for the `ThrottlerModule`
82+
The following options are valid for the `ThrottlerModule`:
8383

8484
<table>
8585
<tr>
@@ -142,4 +142,4 @@ This is doable, as long as `ThrottlerConfigService` implements the interface `Th
142142

143143
The built in storage is an in memory cache that keeps track of the requests made until they have passed the TTL set by the global options. You can drop in your own storage option to the `storage` option of the `ThrottlerModule` so long as the class implements the `ThrottlerStorage` interface.
144144

145-
> **Note** `ThrottlerStorage` can be imported from `@nestjs/throttler`.
145+
> info **Note** `ThrottlerStorage` can be imported from `@nestjs/throttler`.

0 commit comments

Comments
 (0)