Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
feat: use seconds() throttler helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Sep 9, 2023
1 parent 042a30c commit f3a3df9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test/app/controllers/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Controller, Get } from '@nestjs/common';
import { SkipThrottle, Throttle } from '@nestjs/throttler';
import { SkipThrottle, Throttle, seconds } from '@nestjs/throttler';
import { AppService } from '../app.service';

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

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

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

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

@Throttle({ default: { limit: 3, ttl: 10000 } })
@Throttle({ default: { limit: 3, ttl: seconds(10) } })
@Get('flooded')
getFlooded() {
return this.appService.success();
Expand Down

0 comments on commit f3a3df9

Please sign in to comment.