Skip to content

Commit

Permalink
feat: use throttler v5
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Sep 9, 2023
1 parent fbb1047 commit bd96544
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@nestjs/platform-ws": ">=9.4.1",
"@nestjs/schematics": ">=9.2.0",
"@nestjs/testing": ">=9.4.1",
"@nestjs/throttler": "^4.0.0",
"@nestjs/throttler": "^5.0.0",
"@nestjs/websockets": ">=9.4.1",
"@types/express": "^4.17.17",
"@types/jest": "29.5.1",
Expand Down Expand Up @@ -84,7 +84,7 @@
"peerDependencies": {
"@nestjs/common": ">=9.4.1",
"@nestjs/core": ">=9.4.1",
"@nestjs/throttler": ">=4.0.0",
"@nestjs/throttler": ">=5.0.0",
"ioredis": "^5.3.2",
"reflect-metadata": "^0.1.13"
},
Expand Down
2 changes: 1 addition & 1 deletion src/throttler-storage-redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ThrottlerStorageRedisService implements ThrottlerStorageRedis, OnMo
this.scriptSrc,
1,
key,
ttl * 1000,
ttl,
)) as number[];

if (!Array.isArray(results)) {
Expand Down
2 changes: 1 addition & 1 deletion test/app/controllers/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SkipThrottle, Throttle } from '@nestjs/throttler';
import { AppService } from '../app.service';

@Controller()
@Throttle(2, 10)
@Throttle({ default: { limit: 2, ttl: 10000 } })
export class AppController {
constructor(private readonly appService: AppService) {}

Expand Down
3 changes: 1 addition & 2 deletions test/app/controllers/cluster-controller.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { LimitController } from './limit.controller';
@Module({
imports: [
ThrottlerModule.forRoot({
limit: 5,
ttl: 60,
throttlers: [{ limit: 5, ttl: 60000 }],
ignoreUserAgents: [/throttler-test/g],
storage: new ThrottlerStorageRedisService(cluster),
}),
Expand Down
3 changes: 1 addition & 2 deletions test/app/controllers/controller.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { LimitController } from './limit.controller';
@Module({
imports: [
ThrottlerModule.forRoot({
limit: 5,
ttl: 60,
throttlers: [{ limit: 5, ttl: 60000 }],
ignoreUserAgents: [/throttler-test/g],
storage: new ThrottlerStorageRedisService(redis),
}),
Expand Down
6 changes: 3 additions & 3 deletions test/app/controllers/limit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller, Get } from '@nestjs/common';
import { Throttle } from '@nestjs/throttler';
import { AppService } from '../app.service';

@Throttle(2, 10)
@Throttle({ default: { limit: 2, ttl: 10000 } })
@Controller('limit')
export class LimitController {
constructor(private readonly appService: AppService) {}
Expand All @@ -11,13 +11,13 @@ export class LimitController {
return this.appService.success();
}

@Throttle(5, 10)
@Throttle({ default: { limit: 5, ttl: 10000 } })
@Get('higher')
getHigher() {
return this.appService.success();
}

@Throttle(3, 10)
@Throttle({ default: { limit: 3, ttl: 10000 } })
@Get('flooded')
getFlooded() {
return this.appService.success();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1113,10 +1113,10 @@
dependencies:
tslib "2.5.0"

"@nestjs/throttler@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@nestjs/throttler/-/throttler-4.0.0.tgz#9f9c66df62da6ec1b1ad4305e6a3865676e3812f"
integrity sha512-2T2S/hFhxROa/PZRZhHWFkrukxg3T8Db32Y04m6U6j6N2XqFGSKXhjfIbORO8kk/S2jswa9oTX/K12E120tgaQ==
"@nestjs/throttler@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@nestjs/throttler/-/throttler-5.0.0.tgz#013eddcdc1c7e77a8f997a7c896319cb4f7aa905"
integrity sha512-TKf+bpjYpRnSOu8dqi0TmQAPxyvLoO6jFldTq3ToevYDfLtAxBXDTJs8qRRfmHv3wORaJhIbVDtW1dDQuP5wCQ==
dependencies:
md5 "^2.2.1"

Expand Down

0 comments on commit bd96544

Please sign in to comment.