rapidsquirrel/laravel-rate-limiter

一个强大且可定制的Laravel速率限制中间件

dev-main 2024-08-06 23:35 UTC

This package is auto-updated.

Last update: 2024-09-06 23:57:07 UTC


README

此项目为Laravel应用实现了一个速率限制器,提供保护以防止过度请求和潜在滥用。

特性

  • 简单集成Laravel框架。
  • 可配置请求限制。
  • 为特定路由应用速率限制的中间件。

安装

  1. 克隆仓库
git clone https://github.com/amrq88/laravel-rate-limiter.git
cd laravel-rate-limiter
  1. 安装依赖
composer install
  1. 复制示例环境文件并更新环境变量
cp .env.example .env
php artisan key:generate
  1. 运行迁移
php artisan migrate

配置

您可以在config/rate_limiter.php文件中配置速率限制器设置。

return [
    'limits' => [
        'default' => [
            'max_attempts' => 60,
            'decay_minutes' => 1,
        ],
        // Add other rate limit configurations here
    ],
];

使用方法

routes/web.phproutes/api.php中将速率限制器中间件应用到路由上

use App\Http\Middleware\RateLimiter;

Route::middleware([RateLimiter::class])->group(function () {
    Route::get('/your-route', [YourController::class, 'yourMethod']);
});

贡献

如果您想贡献,请分支仓库并按照您的意愿进行更改。Pull requests热烈欢迎。

  1. 分支项目
  2. 创建功能分支(git checkout -b feature/AmazingFeature
  3. 提交您的更改(git commit -m 'Add some AmazingFeature'
  4. 推送到分支(git push origin feature/AmazingFeature
  5. 打开Pull Request

许可证

此项目受MIT许可证许可 - 有关详细信息,请参阅LICENSE文件。

联系方式

如有任何疑问,请联系Amr Qawasmeh