From 21ce13852d12a4931f382785b7aef13fc3b2783f Mon Sep 17 00:00:00 2001 From: Amruth-Vamshi Date: Wed, 13 Sep 2023 15:11:02 +0530 Subject: [PATCH] updated rate limiter gaurd --- src/rate-limiter.guard.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rate-limiter.guard.ts b/src/rate-limiter.guard.ts index cbae0c9..cc9fa3d 100644 --- a/src/rate-limiter.guard.ts +++ b/src/rate-limiter.guard.ts @@ -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 { + 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 { // In this example, we're using the IP address as the key for rate limiting. return request.ip; } -} \ No newline at end of file +} +