diff --git a/packages/api/package.json b/packages/api/package.json index a36a41cf8..bef23bc1e 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -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", diff --git a/packages/api/src/app.module.ts b/packages/api/src/app.module.ts index 194c034c4..e88afc8bc 100644 --- a/packages/api/src/app.module.ts +++ b/packages/api/src/app.module.ts @@ -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: [ @@ -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' ? [ @@ -66,6 +73,10 @@ import { TicketingModule } from '@ticketing/ticketing.module'; AppService, TasksService, LoggerService, + { + provide: APP_GUARD, + useClass: ThrottlerGuard, + }, { provide: APP_INTERCEPTOR, useFactory: () =>