我正在编写大量API来获取和存储数据。
我喜欢默认 throttle
选项:
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
],
];
将请求限制在每分钟60;但是对于某些路线(es: POST
),我想增加这个值。
我试着设定 'throttle:500,1'
路线中间件如下:
Route::group(function () {
Route::get('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@index']);
Route::post('semaphore/1', ['uses' => 'App\Api\V1\DBs\SemaphoreController@store', 'middleware' => 'WriteToDatabaseMiddleware', 'throttle:500,1']);
});
但它不起作用。
任何想法?
谢谢。
更新:
我注意到了 'throttle:500,1'
用于 api.php
路线将在默认设置后设置 'throttle:60,1'
指定成 Kernel.php
文件;那么,它不起作用。
记录流程执行,第一个调用是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
从 Kernel.php
具有 maxAttempts=60
。
然后,第二个电话是:
Illuminate\Routing\Middleware\ThrottleRequests -> handle
从 api.php
具有 maxAttempts=500
。
换句话说, throttle:500,1
在里面 api.php
文件不要覆盖 throttle:60,1
在里面 Kernel.php
文件。