Skip to content

Commit

Permalink
⚡ Added API Rate Limit as described in issue 56, Used nest js package…
Browse files Browse the repository at this point in the history
… throttle for applying rate limit to APIs the throttle limit and throttle ttl are to be added in .env as THROTTLER_LIMIT and THROTTLE_TTL respectively

Added API Rate Limit as described in issue 56, Used nest js package throttle for applying rate limit to APIs the throttle limit and throttle ttl are to be added in .env
  • Loading branch information
sachin.sharma authored and sachin.sharma committed Dec 29, 2023
1 parent 381e975 commit 74e46f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/schedule": "^4.0.0",
"@nestjs/swagger": "^7.1.14",
"@nestjs/throttler": "^5.1.1",
"@ntegral/nestjs-sentry": "^4.0.0",
"@prisma/client": "^5.4.2",
"@sentry/node": "^7.80.0",
Expand Down
13 changes: 12 additions & 1 deletion packages/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { AtsModule } from './ats/ats.module';
import { AccountingModule } from './accounting/accounting.module';
import { FileStorageModule } from './file-storage/file-storage.module';
import { SentryInterceptor, SentryModule } from '@ntegral/nestjs-sentry';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { LoggerService } from '@@core/logger/logger.service';
import { CoreModule } from '@@core/core.module';
import { BullModule } from '@nestjs/bull';
import { TicketingModule } from '@ticketing/ticketing.module';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';

@Module({
imports: [
Expand All @@ -28,6 +29,12 @@ import { TicketingModule } from '@ticketing/ticketing.module';
FileStorageModule,
CrmModule,
TicketingModule,
ThrottlerModule.forRoot([
{
ttl: parseInt(process.env.THROTTLER_TTL),
limit: parseInt(process.env.THROTTLER_LIMIT)
},
]),
ConfigModule.forRoot({ isGlobal: true }),
...(process.env.DISTRIBUTION === 'managed'
? [
Expand Down Expand Up @@ -66,6 +73,10 @@ import { TicketingModule } from '@ticketing/ticketing.module';
AppService,
TasksService,
LoggerService,
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
{
provide: APP_INTERCEPTOR,
useFactory: () =>
Expand Down

0 comments on commit 74e46f9

Please sign in to comment.