Skip to content

Commit cab2bd8

Browse files
authored
Merge branch 'nestjs:master' into update-docs-patch-1
2 parents 5bd6a0d + e02b95a commit cab2bd8

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

content/graphql/scalars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The code-first approach ships with five scalars in which three of them are simpl
1010
- `Int` (alias for `GraphQLInt`) - a signed 32‐bit integer
1111
- `Float` (alias for `GraphQLFloat`) - a signed double-precision floating-point value
1212
- `GraphQLISODateTime` - a date-time string at UTC (used by default to represent `Date` type)
13-
- `GraphQLTimestamp` - a numeric string which represents time and date as number of milliseconds from start of UNIX epoch
13+
- `GraphQLTimestamp` - a signed integer which represents date and time as number of milliseconds from start of UNIX epoch
1414

1515
The `GraphQLISODateTime` (e.g. `2019-12-03T09:54:33Z`) is used by default to represent the `Date` type. To use the `GraphQLTimestamp` instead, set the `dateScalarMode` of the `buildSchemaOptions` object to `'timestamp'` as follows:
1616

content/middlewares.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ consumer.apply(cors(), helmet(), logger).forRoutes(CatsController);
237237
If we want to bind middleware to every registered route at once, we can use the `use()` method that is supplied by the `INestApplication` instance:
238238

239239
```typescript
240+
@@filename(main)
240241
const app = await NestFactory.create(AppModule);
241242
app.use(logger);
242243
await app.listen(3000);

content/recipes/prisma.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export class UserService {
295295
take?: number;
296296
cursor?: Prisma.UserWhereUniqueInput;
297297
where?: Prisma.UserWhereInput;
298-
orderBy?: Prisma.UserOrderByInput;
298+
orderBy?: Prisma.UserOrderByWithRelationInput;
299299
}): Promise<User[]> {
300300
const { skip, take, cursor, where, orderBy } = params;
301301
return this.prisma.user.findMany({
@@ -361,7 +361,7 @@ export class PostService {
361361
take?: number;
362362
cursor?: Prisma.PostWhereUniqueInput;
363363
where?: Prisma.PostWhereInput;
364-
orderBy?: Prisma.PostOrderByInput;
364+
orderBy?: Prisma.PostOrderByWithRelationInput;
365365
}): Promise<Post[]> {
366366
const { skip, take, cursor, where, orderBy } = params;
367367
return this.prisma.post.findMany({

content/security/rate-limiting.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ There may be a time where you want to bind the guard to a controller or globally
3737

3838
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

40+
#### Proxies
41+
42+
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/Server/#trustproxy)) for the `trust proxy` option and enable it. Doing so will allow you to get the original IP address from the `X-Forward-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:
43+
44+
```ts
45+
// throttler-behind-proxy.guard.ts
46+
import { ThrottlerGuard } from '@nestjs/throttler';
47+
import { Injectable } from '@nestjs/common';
48+
49+
@Injectable()
50+
export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
51+
protected getTracker(req: Record<string, any>): string {
52+
return req.ips.length ? req.ips[0] : req.ip; // individualize IP extraction to meet your own needs
53+
}
54+
}
55+
56+
// app.controller.ts
57+
import { ThrottlerBehindProxyGuard } from './throttler-behind-proxy.guard';
58+
59+
@UseGuards(ThrottlerBehindProxyGuard)
60+
```
61+
62+
> info **Hint** You can find the API of the `req` Request object for express [here](https://expressjs.com/en/api.html#req.ips) and for fastify [here](https://www.fastify.io/docs/latest/Request/).
63+
4064
#### Websockets
4165

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

content/techniques/streaming-files.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,25 @@ export class FileController {
4545
}
4646
}
4747
```
48+
49+
The default content type is `application/octet-stream`, if you need to customize the response you can use the `res.set` method.
50+
51+
52+
```ts
53+
import { Controller, Get, StreamableFile, Response } from '@nestjs/common';
54+
import { createReadStream } from 'fs';
55+
import { join } from 'path';
56+
57+
@Controller('file')
58+
export class FileController {
59+
@Get()
60+
getFile(@Response({ passthrough: true }) res): StreamableFile {
61+
const file = createReadStream(join(process.cwd(), 'package.json'));
62+
res.set({
63+
'Content-Type': 'application/json',
64+
'Content-Disposition': 'attachment; filename="package.json"',
65+
});
66+
return new StreamableFile(file);
67+
}
68+
}
69+
```

0 commit comments

Comments
 (0)