Skip to content

Commit 3daa480

Browse files
docs(chore): add skip handler example (#121)
for obf subpaths GH-120
1 parent 4b23299 commit 3daa480

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async resetPassword(
174174
}
175175
```
176176

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

179179
```ts
180180
@ratelimit(false)
@@ -213,14 +213,33 @@ this.bind(RateLimitSecurityBindings.RATELIMITCONFIG).to({
213213
RatelimitActionMiddleware: true,
214214
});
215215

216-
217216
this.component(RateLimiterComponent);
218-
219217
```
220218

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

222+
## Skip Handler
223+
224+
By default all the paths are rate limited based on the configuration provided, but can be skipped using the skip handler.
225+
226+
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.
227+
228+
```diff
229+
const obfPath = process.env.OBF_PATH ?? '/obf';
230+
231+
this.bind(RateLimitSecurityBindings.CONFIG).to({
232+
name: RedisDataSource.dataSourceName,
233+
type: 'RedisStore',
234+
+ skip: (request, response) => {
235+
+ const isOBFSubpath = Boolean(
236+
+ request.path.match(new RegExp(`^/$+{obfPath.replace(/^\//, '')}/.+`)),
237+
+ );
238+
+ return !!isOBFSubpath;
239+
},
240+
});
241+
```
242+
224243
## Feedback
225244

226245
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.

0 commit comments

Comments
 (0)