diff --git a/.swp b/.swp new file mode 100644 index 0000000000..2cab0a0dc2 Binary files /dev/null and b/.swp differ diff --git a/content/security/rate-limiting.md b/content/security/rate-limiting.md index d2b1e86fa8..1fad9116d4 100644 --- a/content/security/rate-limiting.md +++ b/content/security/rate-limiting.md @@ -72,7 +72,23 @@ findAll() { #### Proxies -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: +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. +The following example enables `trust proxy` for the `express` adapter: + +```typescript +//main.ts +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; +import { NestExpressApplication } from "@nestjs/platform-express" +async function bootstrap() { + const app = await NestFactory.create(AppModule); + app.set('trust proxy', 'loopback') // specify a single subnet + await app.listen(3000) +} +bootstrap(); +``` + +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: ```typescript // throttler-behind-proxy.guard.ts