Skip to content

Commit d18f683

Browse files
Merge branch 'my-fix-branch' of https://github.com/lukaszniemkiewicz/docs.nestjs.com into lukaszniemkiewicz-my-fix-branch
2 parents ab68fc6 + a1a767e commit d18f683

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.swp

12 KB
Binary file not shown.

content/security/rate-limiting.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ findAll() {
103103

104104
#### Proxies
105105

106-
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:
106+
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.
107+
The following example enables `trust proxy` for the `express` adapter:
108+
109+
```typescript
110+
//main.ts
111+
import { NestFactory } from '@nestjs/core';
112+
import { AppModule } from './app.module';
113+
import { NestExpressApplication } from "@nestjs/platform-express"
114+
async function bootstrap() {
115+
const app = await NestFactory.create<NestExpressApplication>(AppModule);
116+
app.set('trust proxy', 'loopback') // specify a single subnet
117+
await app.listen(3000)
118+
}
119+
bootstrap();
120+
```
121+
122+
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:
107123

108124
```typescript
109125
// throttler-behind-proxy.guard.ts

0 commit comments

Comments
 (0)