forked from Shared/esg
initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { UserRateLimitService } from './user-rate-limit.service';
|
||||
import { UserRateLimitGuard } from './user-rate-limit.guard';
|
||||
|
||||
/**
|
||||
* Global rate limiting via @nestjs/throttler plus per-user limits for inquiry routes.
|
||||
*/
|
||||
@Module({
|
||||
imports: [
|
||||
UsersModule,
|
||||
ThrottlerModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService) => [
|
||||
{
|
||||
ttl: config.get<number>('throttle.ttl', 60) * 1000,
|
||||
limit: config.get<number>('throttle.limit', 100),
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
providers: [
|
||||
UserRateLimitService,
|
||||
UserRateLimitGuard,
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: ThrottlerGuard,
|
||||
},
|
||||
],
|
||||
/** Re-export UsersModule so importers (e.g. InquiryModule) can resolve UserRateLimitGuard deps. */
|
||||
exports: [UserRateLimitService, UserRateLimitGuard, UsersModule],
|
||||
})
|
||||
export class RateLimitModule {}
|
||||
Reference in New Issue
Block a user