Skip to content

Commit 5ab2fb3

Browse files
Merge branch 'master' into fix/typos
2 parents 18b30d1 + f51b5c4 commit 5ab2fb3

File tree

9 files changed

+3039
-3055
lines changed

9 files changed

+3039
-3055
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14.16.0
1+
14.19.1

content/components.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
### Providers
22

3-
Providers are a fundamental concept in Nest. Many of the basic Nest classes may be treated as a provider – services, repositories, factories, helpers, and so on. The main idea of a provider is that it can be **injected** as dependency; this means objects can create various relationships with each other, and the function of "wiring up" instances of objects can largely be delegated to the Nest runtime system.
3+
Providers are a fundamental concept in Nest. Many of the basic Nest classes may be treated as a provider – services, repositories, factories, helpers, and so on. The main idea of a provider is that it can be **injected** as a dependency; this means objects can create various relationships with each other, and the function of "wiring up" instances of objects can largely be delegated to the Nest runtime system.
44

55
<figure><img src="/assets/Components_1.png" /></figure>
66

77
In the previous chapter, we built a simple `CatsController`. Controllers should handle HTTP requests and delegate more complex tasks to **providers**. Providers are plain JavaScript classes that are declared as `providers` in a [module](/modules).
88

9-
> info **Hint** Since Nest enables the possibility to design and organize dependencies in a more OO-way, we strongly recommend following the [SOLID](https://en.wikipedia.org/wiki/SOLID) principles.
9+
> info **Hint** Since Nest enables the possibility to design and organize dependencies in a more OO way, we strongly recommend following the [SOLID](https://en.wikipedia.org/wiki/SOLID) principles.
1010
1111
#### Services
1212

@@ -50,7 +50,7 @@ export class CatsService {
5050

5151
> info **Hint** To create a service using the CLI, simply execute the `$ nest g service cats` command.
5252
53-
Our `CatsService` is a basic class with one property and two methods. The only new feature is that it uses the `@Injectable()` decorator. The `@Injectable()` decorator attaches metadata, which declares that `CatsService` is a class that can be managed by the Nest IoC container. By the way, this example also uses a `Cat` interface, which probably looks something like this:
53+
Our `CatsService` is a basic class with one property and two methods. The only new feature is that it uses the `@Injectable()` decorator. The `@Injectable()` decorator attaches metadata, which declares that `CatsService` is a class that can be managed by the Nest [IoC](https://en.wikipedia.org/wiki/Inversion_of_control) container. By the way, this example also uses a `Cat` interface, which probably looks something like this:
5454

5555
```typescript
5656
@@filename(interfaces/cat.interface)

content/fundamentals/unit-testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ Instead of using the production version of any provider, you can override it wit
165165
Nest also allows you to define a mock factory to apply to all of your missing dependencies. This is useful for cases where you have a large number of dependencies in a class and mocking all of them will take a long time and a lot of setup. To make use of this feature, the `createTestingModule()` will need to be chained up with the `useMocker()` method, passing a factory for your dependency mocks. This factory can take in an optional token, which is an instance token, any token which is valid for a Nest provider, and returns a mock implementation. The below is an example of creating a generic mocker using [`jest-mock`](https://www.npmjs.com/package/jest-mock) and a specific mock for `CatsService` using `jest.fn()`.
166166

167167
```typescript
168+
// ...
169+
import { ModuleMocker } from 'jest-mock';
170+
168171
const moduleMocker = new ModuleMocker(global);
169172

170173
describe('CatsController', () => {

content/security/rate-limiting.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,46 @@ Once the module has been imported, you can then choose how you would like to bin
3535

3636
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+
```typescript
39+
@SkipThrottle()
40+
@Controller('users')
41+
export class UsersController {}
42+
```
43+
44+
This `@SkipThrottle()` decorator can be used to skip a route or a class or to negate the skipping of a route in a class that is skipped.
45+
46+
```typescript
47+
@SkipThrottle()
48+
@Controller('users')
49+
export class UsersController {
50+
// Rate limiting is applied to this route.
51+
@SkipThrottle(false)
52+
dontSkip() {
53+
return "List users work with Rate limiting.";
54+
}
55+
// This route will skip rate limiting.
56+
doSkip() {
57+
return "List users work without Rate limiting.";
58+
}
59+
}
60+
```
61+
62+
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`. You have to configure it like this:
63+
64+
```typescript
65+
// Override default configuration for Rate limiting and duration.
66+
@Throttle(3, 60)
67+
@Get()
68+
findAll() {
69+
return "List users works with custom rate limiting.";
70+
}
71+
```
3972

4073
#### Proxies
4174

4275
If your application runs behind a proxy server, check the specific HTTP adapter options ([express](http://expressjs.com/en/guide/behind-proxies.html) and [fastify](https://www.fastify.io/docs/latest/Reference/Server/#trustproxy)) for the `trust proxy` option and enable it. Doing so will allow you to get the original IP address from the `X-Forwarded-For` header, and you can override the `getTracker()` method to pull the value from the header rather than from `req.ip`. The following example works with both express and fastify:
4376

44-
```ts
77+
```typescript
4578
// throttler-behind-proxy.guard.ts
4679
import { ThrottlerGuard } from '@nestjs/throttler';
4780
import { Injectable } from '@nestjs/common';

content/techniques/cookies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const app = await NestFactory.create<NestFastifyApplication>(
7171
AppModule,
7272
new FastifyAdapter(),
7373
);
74-
app.register(fastifyCookie, {
74+
await app.register(fastifyCookie, {
7575
secret: 'my-secret', // for cookies signature
7676
});
7777
```

content/techniques/sessions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const app = await NestFactory.create<NestFastifyApplication>(
7777
AppModule,
7878
new FastifyAdapter(),
7979
);
80-
app.register(secureSession, {
80+
await app.register(secureSession, {
8181
secret: 'averylogphrasebiggerthanthirtytwochars',
8282
salt: 'mq9hDxBVDbspDR6n',
8383
});

0 commit comments

Comments
 (0)