Skip to content

Commit

Permalink
🔒 Add rate limit for whole application routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 16, 2024
1 parent 67ab309 commit d4426ee
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
2 changes: 2 additions & 0 deletions src/modules/misc/version.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/modules/webtoon/webtoon/webtoon.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d4426ee

Please sign in to comment.