web-api/app/Providers/AppServiceProvider.php
梁朝伟 7f3db2ed48 init
2024-11-13 19:23:49 +08:00

31 lines
750 B
PHP

<?php
namespace App\Providers;
use App\Foundation\PersonalAccessToken;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Sanctum\Sanctum;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void {}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
RateLimiter::for('api', function ($request) {
$key = sha1($request->ip() . $request->header('User-Agent'));
return Limit::perMinute(10)->by($key);
});
}
}