From d6bf4d3cb31ed73597ccbfc4ec5013c258077075 Mon Sep 17 00:00:00 2001 From: tone Date: Thu, 18 Dec 2025 11:48:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=99=90=E6=B5=81=E3=80=81=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E7=88=AC=E8=99=AB=E3=80=81=E8=B0=83=E6=95=B4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=99=90=E6=B5=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/app.module.ts | 5 +++-- apps/backend/src/sms/sms.controller.ts | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index a579ad0..0759ac0 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -30,9 +30,10 @@ import { SmsModule } from './sms/sms.module'; synchronize: process.env.NODE_ENV !== 'production', // Set to false in production }), ThrottlerModule.forRoot({ + ignoreUserAgents: [/googlebot/i, /bingbot/i], throttlers: [ { - limit: 1000, + limit: 100, ttl: 60000, // 1 minute }, ], @@ -51,4 +52,4 @@ import { SmsModule } from './sms/sms.module'; controllers: [AppController], providers: [AppService], }) -export class AppModule {} +export class AppModule { } diff --git a/apps/backend/src/sms/sms.controller.ts b/apps/backend/src/sms/sms.controller.ts index d5d688a..1a22ee6 100644 --- a/apps/backend/src/sms/sms.controller.ts +++ b/apps/backend/src/sms/sms.controller.ts @@ -1,6 +1,7 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Post, UseGuards } from '@nestjs/common'; import { SendLoginSmsDto } from './dto/send-login-sms.dto'; import { SmsService } from './sms.service'; +import { Throttle, ThrottlerGuard } from '@nestjs/throttler'; @Controller('sms') export class SmsController { @@ -8,6 +9,8 @@ export class SmsController { constructor(private readonly smsService: SmsService) { } @Post('send/login') + @UseGuards(ThrottlerGuard) + @Throttle({ sms_login: { limit: 10, ttl: 60000 } }) async sendLoginSms(@Body() dto: SendLoginSmsDto) { await this.smsService.sendSms(dto.phone, 'login'); return null;