Skip to content

Commit

Permalink
docs(chore): add skip handler example (#121)
Browse files Browse the repository at this point in the history
for obf subpaths

GH-120
  • Loading branch information
Surbhi-sharma1 authored Jul 14, 2023
1 parent 4b23299 commit 3daa480
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async resetPassword(
}
```

- You can also disable rate limiting for specific API methods using the decorator like below.
- You can also disable rate limiting for specific API methods using the decorator like below or use the [skip handler](#skip-handler)

```ts
@ratelimit(false)
Expand Down Expand Up @@ -213,14 +213,33 @@ this.bind(RateLimitSecurityBindings.RATELIMITCONFIG).to({
RatelimitActionMiddleware: true,
});


this.component(RateLimiterComponent);

```

This binding needs to be done before adding the RateLimiter component to your application.
Apart from this all other steps will remain the same.

## Skip Handler

By default all the paths are rate limited based on the configuration provided, but can be skipped using the skip handler.

Following is the example of an handler that returns true if the path starts with `/obf/` such as `/obf/css/style.css`, `/obf/fonts`, `/obf/stats` etc.

```diff
const obfPath = process.env.OBF_PATH ?? '/obf';

this.bind(RateLimitSecurityBindings.CONFIG).to({
name: RedisDataSource.dataSourceName,
type: 'RedisStore',
+ skip: (request, response) => {
+ const isOBFSubpath = Boolean(
+ request.path.match(new RegExp(`^/$+{obfPath.replace(/^\//, '')}/.+`)),
+ );
+ return !!isOBFSubpath;
},
});
```

## Feedback

If you've noticed a bug or have a question or have a feature request, [search the issue tracker](https://github.com/sourcefuse/loopback4-ratelimiter/issues) to see if someone else in the community has already created a ticket.
Expand Down

0 comments on commit 3daa480

Please sign in to comment.