feat: add throttler
This commit is contained in:
+3
-8
@@ -83,14 +83,9 @@ const ENV = process.env.NODE_ENV;
|
||||
// Schedule
|
||||
ScheduleModule.forRoot(),
|
||||
|
||||
// Throttler
|
||||
// ThrottlerModule.forRoot([
|
||||
// { name: 'default', limit: 100, ttl: 60_000 },
|
||||
// { name: 'login', limit: 5, ttl: 60_000 },
|
||||
// { name: 'otp', limit: 3, ttl: 300_000 },
|
||||
// { name: 'admin', limit: 30, ttl: 60_000 },
|
||||
// ]),
|
||||
ThrottlerModule.forRoot([]),
|
||||
// Generous per-IP, per-endpoint limits for the MVP. Sensitive routes
|
||||
// override this same bucket so their limits do not affect other routes.
|
||||
ThrottlerModule.forRoot([{ name: 'default', limit: 300, ttl: 60_000 }]),
|
||||
|
||||
// Logging
|
||||
LoggingModule,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Public } from '@/modules/auth/decorators/public.decorator';
|
||||
import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/auth')
|
||||
@Throttle({ login: {} })
|
||||
@Throttle({ default: { limit: 30, ttl: 60_000 } })
|
||||
export class AdminAuthController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/choices')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
@Throttle({ admin: {} })
|
||||
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
||||
export class AdminChoicesController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/question-transitions')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
@Throttle({ admin: {} })
|
||||
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
||||
export class AdminQuestionTransitionsController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/questions')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
@Throttle({ admin: {} })
|
||||
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
||||
export class AdminQuestionsController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/scoring')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
@Throttle({ admin: {} })
|
||||
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
||||
export class AdminScoringController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('admin/tests')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
@Throttle({ admin: {} })
|
||||
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
||||
export class AdminTestsController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ export class AuthController {
|
||||
@Public()
|
||||
@Post('login')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Throttle({ login: {} })
|
||||
@Throttle({ default: { limit: 30, ttl: 60_000 } })
|
||||
@ApiAppResponse([
|
||||
{
|
||||
status: HttpStatus.OK,
|
||||
@@ -86,7 +86,7 @@ export class AuthController {
|
||||
@Public()
|
||||
@Post('verify-otp')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Throttle({ otp: {} })
|
||||
@Throttle({ default: { limit: 30, ttl: 60_000 } })
|
||||
@ApiAppResponse([
|
||||
{
|
||||
status: HttpStatus.OK,
|
||||
@@ -112,7 +112,7 @@ export class AuthController {
|
||||
@Public()
|
||||
@Post('refresh')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Throttle({ login: {} })
|
||||
@Throttle({ default: { limit: 60, ttl: 60_000 } })
|
||||
@ApiAppResponse([
|
||||
{
|
||||
status: HttpStatus.OK,
|
||||
|
||||
@@ -12,8 +12,10 @@ import { ChatDTO } from './dtos/chat.dto';
|
||||
import { ActiveUser } from '@/common/decorators/active-user.decorator';
|
||||
import { User } from '../users/entities/user.entity';
|
||||
import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator';
|
||||
import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('chatbot')
|
||||
@Throttle({ default: { limit: 30, ttl: 60_000 } })
|
||||
export class ChatbotController {
|
||||
constructor(
|
||||
/**
|
||||
|
||||
@@ -24,9 +24,9 @@ import { StartGuestDTO } from './dtos/responses/start-guest.dto';
|
||||
import { GetAnswerSubmissionDTO } from './dtos/responses/get-answer-submission.dto';
|
||||
import { GetSubmissionHistoryDTO } from './dtos/responses/get-submission-history.dto';
|
||||
import { GetSubmissionDetailDTO } from './dtos/responses/get-submission-detail.dto';
|
||||
import type { Response } from 'express';
|
||||
import { Observable } from 'rxjs';
|
||||
import { I18nService } from 'nestjs-i18n';
|
||||
import { Throttle } from '@nestjs/throttler';
|
||||
|
||||
@Controller('submissions')
|
||||
export class SubmissionsController {
|
||||
@@ -173,6 +173,7 @@ export class SubmissionsController {
|
||||
}
|
||||
|
||||
@Sse(':id/analyze')
|
||||
@Throttle({ default: { limit: 30, ttl: 60_000 } })
|
||||
@ApiProduces('text/event-stream')
|
||||
@ApiResponse({
|
||||
status: HttpStatus.OK,
|
||||
|
||||
Reference in New Issue
Block a user