Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: deactivate rate limiting correctly (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan authored Sep 21, 2023
1 parent 05facdf commit c973a67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions packages/backend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const THROTTLER_TTL_SECONDS = process.env.THROTTLER_TTL_SECONDS
// }),
FaucetModule,
],
providers: [
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
],
// providers: [
// {
// provide: APP_GUARD,
// useClass: ThrottlerGuard,
// },
// ],
})
export class AppModule {}
4 changes: 2 additions & 2 deletions packages/backend/src/faucet/faucet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common'

import { GetSubnetAssetsDto } from './faucet.dto'
import { FaucetService } from './faucet.service'
import { ThrottlerBehindProxyGuard } from './throttler.guard'
// import { ThrottlerBehindProxyGuard } from './throttler.guard'

@Controller('faucet')
export class FaucetController {
constructor(private faucetService: FaucetService) {}

@Post('getSubnetAssets')
@UseGuards(ThrottlerBehindProxyGuard)
// @UseGuards(ThrottlerBehindProxyGuard)
async getSubnetAssets(
@Body() getSubnetAssetsDto: GetSubnetAssetsDto,
@Headers('traceparent') traceparent: string
Expand Down
30 changes: 15 additions & 15 deletions packages/backend/src/faucet/throttler.guard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ThrottlerGuard } from '@nestjs/throttler'
import { Injectable } from '@nestjs/common'
// import { ThrottlerGuard } from '@nestjs/throttler'
// import { Injectable } from '@nestjs/common'

@Injectable()
export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
protected getTracker(req: Record<string, any>) {
console.log('headers', req.headers)
console.log('x-forwarded-for', req.headers['x-forwarded-for'])
console.log('connection.remoteAddress', req.connection.remoteAddress)
console.log('IPs from request headers', req.ips)
console.log('IP from request', req.ip)
return req.headers['x-forwarded-for']
? req.headers['x-forwarded-for']
: req.ip
}
}
// @Injectable()
// export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
// protected getTracker(req: Record<string, any>) {
// console.log('headers', req.headers)
// console.log('x-forwarded-for', req.headers['x-forwarded-for'])
// console.log('connection.remoteAddress', req.connection.remoteAddress)
// console.log('IPs from request headers', req.ips)
// console.log('IP from request', req.ip)
// return req.headers['x-forwarded-for']
// ? req.headers['x-forwarded-for']
// : req.ip
// }
// }

0 comments on commit c973a67

Please sign in to comment.