42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\UserGame;
|
|
use App\Policies\UserGamePolicy;
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Gate::policy(UserGame::class, UserGamePolicy::class);
|
|
Gate::policy(\App\Models\Review::class, \App\Policies\ReviewPolicy::class);
|
|
Gate::policy(\App\Models\UserList::class, \App\Policies\ListPolicy::class);
|
|
Gate::policy(\App\Models\GameComment::class, \App\Policies\GameCommentPolicy::class);
|
|
Gate::policy(\App\Models\ApiKey::class, \App\Policies\ApiKeyPolicy::class);
|
|
|
|
RateLimiter::for('api', function (Request $request) {
|
|
$key = $request->bearerToken() ?? $request->get('api_key') ?? $request->ip();
|
|
return Limit::perMinute(60)->by($key)->response(function () {
|
|
return response()->json(['error' => 'Too many requests. Limit: 60/min.'], 429);
|
|
});
|
|
});
|
|
}
|
|
}
|