You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> warning **Warning**`cache-manager` version 4 uses seconds for `TTL (Time-To-Live)`. The current version of `cache-manager` (v5) has switched to using milliseconds instead. NestJS doesn't convert the value, and simply forwards the ttl you provide to the library. In other words:
14
-
> * If using `cache-manager` v4, provide ttl in seconds
15
-
> * If using `cache-manager` v5, provide ttl in milliseconds
16
-
> * Documentation is referring to seconds, since NestJS was released targeting version 4 of cache-manager.
14
+
>
15
+
> - If using `cache-manager` v4, provide ttl in seconds
16
+
> - If using `cache-manager` v5, provide ttl in milliseconds
17
+
> - Documentation is referring to seconds, since NestJS was released targeting version 4 of cache-manager.
17
18
18
19
#### In-memory cache
19
20
@@ -315,6 +316,18 @@ This works the same as `useClass` with one critical difference - `CacheModule` w
315
316
316
317
> info **Hint** `CacheModule#register` and `CacheModule#registerAsync` and `CacheOptionsFactory` has an optional generic (type argument) to narrow down store-specific configuration options, making it type safe.
317
318
319
+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
320
+
321
+
```typescript
322
+
CacheModule.registerAsync({
323
+
imports: [ConfigModule],
324
+
useClass: ConfigService,
325
+
extraProviders: [MyAdditionalProvider],
326
+
});
327
+
```
328
+
329
+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
330
+
318
331
#### Example
319
332
320
333
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/20-cache).
`FileValidator` is a regular class that has access to the file object and validates it according to the options provided by the client. Nest has two built-in `FileValidator` implementations you can use in your project:
119
119
120
120
-`MaxFileSizeValidator` - Checks if a given file's size is less than the provided value (measured in `bytes`)
121
-
-`FileTypeValidator` - Checks if a given file's mime-type matches the given value.
121
+
-`FileTypeValidator` - Checks if a given file's mime-type matches the given value.
122
122
123
123
> warning **Warning** To verify file type, [FileTypeValidator](https://github.com/nestjs/nest/blob/master/packages/common/pipes/file/file-type.validator.ts) class uses the type as detected by multer. By default, multer derives file type from file extension on user's device. However, it does not check actual file contents. As files can be renamed to arbitrary extensions, consider using a custom implementation (like checking the file's [magic number](https://www.ibm.com/support/pages/what-magic-number)) if your app requires a safer solution.
124
124
@@ -135,6 +135,7 @@ To understand how these can be used in conjunction with the aforementioned `File
135
135
)
136
136
file: Express.Multer.File,
137
137
```
138
+
138
139
> info **Hint** If the number of validators increase largely or their options are cluttering the file, you can define this array in a separate file and import it here as a named constant like `fileValidators`.
139
140
140
141
Finally, you can use the special `ParseFilePipeBuilder` class that lets you compose & construct your validators. By using it as shown below you can avoid manual instantiation of each validator and just pass their options directly:
@@ -318,6 +319,18 @@ MulterModule.registerAsync({
318
319
});
319
320
```
320
321
322
+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
323
+
324
+
```typescript
325
+
MulterModule.registerAsync({
326
+
imports: [ConfigModule],
327
+
useClass: ConfigService,
328
+
extraProviders: [MyAdditionalProvider],
329
+
});
330
+
```
331
+
332
+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
333
+
321
334
#### Example
322
335
323
336
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/29-file-upload).
Copy file name to clipboardExpand all lines: content/techniques/http-module.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,18 @@ HttpModule.registerAsync({
132
132
});
133
133
```
134
134
135
+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
136
+
137
+
```typescript
138
+
HttpModule.registerAsync({
139
+
imports: [ConfigModule],
140
+
useClass: HttpConfigService,
141
+
extraProviders: [MyAdditionalProvider],
142
+
});
143
+
```
144
+
145
+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
146
+
135
147
#### Using Axios directly
136
148
137
149
If you think that `HttpModule.register`'s options are not enough for you, or if you just want to access the underlying Axios instance created by `@nestjs/axios`, you can access it via `HttpService#axiosRef` as follows:
0 commit comments