Skip to content

Commit

Permalink
Rate limiter whitelist of IP address
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Apr 17, 2024
1 parent 819c12a commit 2b43897
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function boot()
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
if (in_array($request->ip(), config('app.rate_limiter.whitelisted_ip_addresses'))) {
return Limit::none();
}

return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
RateLimiter::for('downloads', function (Request $request) {
Expand Down
6 changes: 6 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,10 @@

'iip_private' => env('IIP_PRIVATE', 'http://127.0.0.1:8002'),
'iip_public' => env('IIP_PUBLIC', 'https://img.webumenia.sk'),

'rate_limiter' => [
'whitelisted_ip_addresses' => env('RATE_LIMITER_WHITELISTED_IP_ADDRESSES')
? explode(',', env('RATE_LIMITER_WHITELISTED_IP_ADDRESSES'))
: [],
],
];

0 comments on commit 2b43897

Please sign in to comment.