Skip to content

Commit

Permalink
updated rate limiter gaurd
Browse files Browse the repository at this point in the history
  • Loading branch information
Amruth-Vamshi committed Sep 13, 2023
1 parent 2d1726e commit 21ce138
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rate-limiter.guard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { Injectable } from '@nestjs/common';
import { ExecutionContext, Injectable } from '@nestjs/common';
import { ThrottlerGuard } from '@nestjs/throttler';
import { Request } from 'express';

@Injectable()
export class RateLimiterGuard extends ThrottlerGuard {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
console.log("canActivate")
console.log(request.context.config.url)

// Check if the request path is "/metrics"
if (request.context.config.url === '/metrics') {
return true; // Bypass rate limiting for "/metrics"
}

// For other routes, apply rate limiting
return super.canActivate(context);
}

async getKey(request: Request): Promise<string> {
// In this example, we're using the IP address as the key for rate limiting.
return request.ip;
}
}
}

0 comments on commit 21ce138

Please sign in to comment.