diff --git a/README.md b/README.md index e628f54ae..6c87b9e5d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ For an overview of the community storage providers, see [Community Storage Provi This package comes with a couple of goodies that should be mentioned, first is the `ThrottlerModule`. - ## Installation ```bash @@ -203,6 +202,55 @@ You can use the `ignoreUserAgents` key to ignore specific user agents. export class AppModule {} ``` +### Ignoring by a logic + +You can use the `skip`. `skip` can return a Promise of boolean. + +```ts +@Module({ + imports: [ + ThrottlerModule.forRoot({ + ttl: 60, + limit: 10, + skip(context, req, res) { + return req.ip === 'google-bot-ip'; + } + }), + ], +}) +``` + +Override by `@SkipThrottle` + +```ts +@Controller() +@SkipThrottle((context, req, res) => req.ip === 'another-ip') +class Controller { + @Get() // skip when req.ip === 'another-ip' + async index() { + return ''; + } + + @Get('root-setting') + @SkipThrottle(false) // skip when req.ip === 'google-bot-ip' + async useDefault() { + return ''; + } + + @Get('method-setting') + @SkipThrottle((context, req, res) => req.ip === 'another-ip-1') // skip when req.ip === 'another-ip-1' + async useMethod() { + return ''; + } + + @Get('dont-skip-at-all') + @SkipThrottle(null) // don't skip at all + async dontSkipAtAll() { + return ''; + } +} +``` + ### ThrottlerStorage Interface to define the methods to handle the details when it comes to keeping track of the requests. @@ -306,4 +354,4 @@ Feel free to submit a PR with your custom storage provider being added to this l ## License -Nest is [MIT licensed](LICENSE). \ No newline at end of file +Nest is [MIT licensed](LICENSE).