From 1a5c3d4013bdd3960a60b6810ba2c2a9d66f1e33 Mon Sep 17 00:00:00 2001 From: mrcfps Date: Fri, 24 Jan 2025 10:08:13 +0800 Subject: [PATCH] fix(api): add redis-based throttler back --- apps/api/src/app.module.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app.module.ts b/apps/api/src/app.module.ts index 9a3fa3be1..ae836827e 100644 --- a/apps/api/src/app.module.ts +++ b/apps/api/src/app.module.ts @@ -1,8 +1,10 @@ import { ExecutionContext, Module } from '@nestjs/common'; import { BullModule } from '@nestjs/bullmq'; +import { APP_GUARD } from '@nestjs/core'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { LoggerModule } from 'nestjs-pino'; import { SkipThrottle, ThrottlerGuard, ThrottlerModule, seconds } from '@nestjs/throttler'; +import { ThrottlerStorageRedisService } from '@nest-lab/throttler-storage-redis'; import api from '@opentelemetry/api'; import { CommonModule } from '@/common/common.module'; @@ -25,7 +27,6 @@ import { CanvasModule } from './canvas/canvas.module'; import { CollabModule } from './collab/collab.module'; import { ActionModule } from './action/action.module'; import { RedisService } from '@/common/redis.service'; -import { APP_GUARD } from '@nestjs/core'; class CustomThrottlerGuard extends ThrottlerGuard { protected async shouldSkip(context: ExecutionContext): Promise { @@ -60,7 +61,7 @@ class CustomThrottlerGuard extends ThrottlerGuard { }, ], getTracker: (req) => (req.ips?.length ? req.ips[0] : req.ip), - // storage: new ThrottlerStorageRedisService(redis), + storage: new ThrottlerStorageRedisService(redis), }), }), LoggerModule.forRoot({