From f2a8ed141c2c41e666085b21427b3d7016c4e356 Mon Sep 17 00:00:00 2001 From: Mhd Zayd Skaff Date: Sun, 22 Jun 2025 10:23:37 +0300 Subject: [PATCH] test throttle module --- src/app.module.ts | 14 ++++++++------ src/main.ts | 7 ------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index ce64932..a50c23f 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,7 +1,7 @@ import { SeederModule } from '@app/common/seed/seeder.module'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { APP_INTERCEPTOR } from '@nestjs/core'; +import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'; import { WinstonModule } from 'nest-winston'; import { AuthenticationModule } from './auth/auth.module'; import { AutomationModule } from './automation/automation.module'; @@ -35,18 +35,20 @@ import { UserNotificationModule } from './user-notification/user-notification.mo import { UserModule } from './users/user.module'; import { VisitorPasswordModule } from './vistor-password/visitor-password.module'; +import { ThrottlerModule } from '@nestjs/throttler/dist/throttler.module'; import { winstonLoggerOptions } from '../libs/common/src/logger/services/winston.logger'; import { AqiModule } from './aqi/aqi.module'; import { OccupancyModule } from './occupancy/occupancy.module'; import { WeatherModule } from './weather/weather.module'; +import { ThrottlerGuard } from '@nestjs/throttler'; @Module({ imports: [ ConfigModule.forRoot({ load: config, }), - /* ThrottlerModule.forRoot({ - throttlers: [{ ttl: 100000, limit: 30 }], - }), */ + ThrottlerModule.forRoot({ + throttlers: [{ ttl: 60000, limit: 30 }], + }), WinstonModule.forRoot(winstonLoggerOptions), ClientModule, AuthenticationModule, @@ -88,10 +90,10 @@ import { WeatherModule } from './weather/weather.module'; provide: APP_INTERCEPTOR, useClass: LoggingInterceptor, }, - /* { + { provide: APP_GUARD, useClass: ThrottlerGuard, - }, */ + }, ], }) export class AppModule {} diff --git a/src/main.ts b/src/main.ts index e00dca6..61e0a8b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,13 +22,6 @@ async function bootstrap() { app.use(new RequestContextMiddleware().use); - app.use( - rateLimit({ - windowMs: 5 * 60 * 1000, - max: 500, - }), - ); - app.use((req, res, next) => { console.log('Real IP:', req.ip); next();