Skip to content

Commit 541ba14

Browse files
committed
feat: add throttling functionality with @nestjs/throttler for rate limiting
1 parent 8a3d28c commit 541ba14

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@nestjs/passport": "^10.0.3",
3333
"@nestjs/platform-express": "^10.4.15",
3434
"@nestjs/swagger": "^7.4.2",
35+
"@nestjs/throttler": "^6.3.0",
3536
"@types/passport-discord": "^0.1.14",
3637
"@types/uuid": "^9.0.8",
3738
"axios": "^1.7.9",

server/src/app.module.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SeedModule } from './seed/seed.module';
1414
import { SongModule } from './song/song.module';
1515
import { SongBrowserModule } from './song-browser/song-browser.module';
1616
import { UserModule } from './user/user.module';
17+
import { ThrottlerModule } from '@nestjs/throttler';
1718

1819
@Module({
1920
imports: [
@@ -63,6 +64,29 @@ import { UserModule } from './user/user.module';
6364
},
6465
inject: [ConfigService],
6566
}),
67+
// Throttler
68+
ThrottlerModule.forRoot([
69+
{
70+
name: 'global',
71+
ttl: 60 * 1000, // 1 minute
72+
limit: 200, // 200 requests per minute
73+
},
74+
{
75+
name: 'short',
76+
ttl: 1000, // 1 second
77+
limit: 5,
78+
},
79+
{
80+
name: 'medium',
81+
ttl: 60 * 1000, // 1 minute
82+
limit: 100,
83+
},
84+
{
85+
name: 'long',
86+
ttl: 60 * 60 * 100, // 1 hour
87+
limit: 1000,
88+
},
89+
]),
6690
SongModule,
6791
UserModule,
6892
AuthModule.forRootAsync(),

0 commit comments

Comments
 (0)