Skip to content

Commit

Permalink
#28 feat: Create rate limit for API
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Dec 10, 2024
1 parent 749c123 commit 179fab7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace CSlant\Blog\ApiPackage\Providers;

use Botble\Theme\Facades\Theme;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;

class RouteServiceProvider extends ServiceProvider
{
/**
* Move base routes to a service provider to make sure all filters & actions can hook to base routes
*/
public function boot(): void
{
// add rate limit for api
$this->configureRateLimiting();
}

protected function configureRateLimiting(): void
{
RateLimiter::for((string) config('blog-api.defaults.route_prefix'), function (Request $request) {
return Limit::perMinute(40)->by(optional($request->user())->id ?: $request->ip());
});
}
}

0 comments on commit 179fab7

Please sign in to comment.