diff --git a/package.json b/package.json index 23a2b16..916c34b 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@nestjs/core": "^10.3.8", "@nestjs/platform-fastify": "^10.3.8", "@nestjs/swagger": "^7.3.1", + "@nestjs/throttler": "^5.1.2", "@prisma/client": "5.13.0", "axios": "^1.6.8", "class-transformer": "^0.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fa8d0f..f6ddfbb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ dependencies: '@nestjs/swagger': specifier: ^7.3.1 version: 7.3.1(@fastify/static@7.0.4)(@nestjs/common@10.3.8)(@nestjs/core@10.3.8)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2) + '@nestjs/throttler': + specifier: ^5.1.2 + version: 5.1.2(@nestjs/common@10.3.8)(@nestjs/core@10.3.8)(reflect-metadata@0.2.2) '@prisma/client': specifier: 5.13.0 version: 5.13.0(prisma@5.14.0) @@ -1387,6 +1390,18 @@ packages: tslib: 2.6.2 dev: true + /@nestjs/throttler@5.1.2(@nestjs/common@10.3.8)(@nestjs/core@10.3.8)(reflect-metadata@0.2.2): + resolution: {integrity: sha512-60MqhSLYUqWOgc38P6C6f76JIpf6mVjly7gpuPBCKtVd0p5e8Fq855j7bJuO4/v25vgaOo1OdVs0U1qtgYioGw==} + peerDependencies: + '@nestjs/common': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 + '@nestjs/core': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 + reflect-metadata: ^0.1.13 || ^0.2.0 + dependencies: + '@nestjs/common': 10.3.8(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/core': 10.3.8(@nestjs/common@10.3.8)(reflect-metadata@0.2.2)(rxjs@7.8.1) + reflect-metadata: 0.2.2 + dev: false + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} diff --git a/src/app.module.ts b/src/app.module.ts index 3656353..681661f 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,15 +3,26 @@ import {TaskModule} from "./modules/task/task.module"; import {ConfigModule} from "@nestjs/config"; import {WebtoonModule} from "./modules/webtoon/webtoon/webtoon.module"; import {AdminModule} from "./modules/webtoon/admin/admin.module"; +import {ThrottlerGuard, ThrottlerModule} from "@nestjs/throttler"; +import {APP_GUARD} from "@nestjs/core"; @Module({ imports: [ ConfigModule.forRoot({isGlobal: true}), + ThrottlerModule.forRoot([{ + ttl: 60000, + limit: 50, + }]), TaskModule, WebtoonModule, AdminModule, ], controllers: [], - providers: [], + providers: [ + { + provide: APP_GUARD, + useClass: ThrottlerGuard + } + ], }) export class AppModule{} diff --git a/src/modules/misc/version.controller.ts b/src/modules/misc/version.controller.ts index f7796e3..89e6814 100644 --- a/src/modules/misc/version.controller.ts +++ b/src/modules/misc/version.controller.ts @@ -2,10 +2,12 @@ import {Controller, Get} from "@nestjs/common"; import {ApiResponse, ApiTags} from "@nestjs/swagger"; import {VersionResponse} from "./models/responses/version.response"; import {ConfigService} from "@nestjs/config"; +import {Throttle} from "@nestjs/throttler"; @Controller("version") @ApiTags("Version") +@Throttle({default: {limit: 100, ttl: 60000}}) export class VersionController{ constructor( diff --git a/src/modules/webtoon/webtoon/webtoon.controller.ts b/src/modules/webtoon/webtoon/webtoon.controller.ts index 0e9081b..8d46450 100644 --- a/src/modules/webtoon/webtoon/webtoon.controller.ts +++ b/src/modules/webtoon/webtoon/webtoon.controller.ts @@ -6,10 +6,12 @@ import {EpisodeIdDto} from "./models/dto/episode-id.dto"; import EpisodesResponse from "./models/responses/episodes.response"; import EpisodeResponse from "./models/responses/episode.response"; import WebtoonResponse from "./models/responses/webtoon.response"; +import {Throttle} from "@nestjs/throttler"; @Controller("webtoons") @ApiTags("Webtoon") +@Throttle({default: {limit: 15, ttl: 60000}}) export class WebtoonController{ constructor(