Skip to content

Commit

Permalink
频率限制
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 2, 2020
1 parent 30a9d51 commit 149ab3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
13 changes: 13 additions & 0 deletions config/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
/*
* 接口频率限制
*/
'rate_limits' => [
// 访问频率限制,次数/分钟
'access' => env('RATE_LIMITS', '60,1'),
// 登录相关,次数/分钟
'sign' => env('SIGN_RATE_LIMITS', '10,1'),
],
];
28 changes: 20 additions & 8 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::prefix('v1')->namespace('Api')->name('api.v1.')->group(function () {
// 短信验证码
Route::post('verificationCodes', 'VerificationCodesController@store')
->name('verificationCodes.store');
// 用户注册
Route::post('users', 'UsersController@store')
->name('users.store');
});
Route::prefix('v1')
->namespace('Api')
->name('api.v1.')
->group(function () {

Route::middleware('throttle:' . config('api.rate_limits.sign'))
->group(function () {
// 短信验证码
Route::post('verificationCodes', 'VerificationCodesController@store')
->name('verificationCodes.store');
// 用户注册
Route::post('users', 'UsersController@store')
->name('users.store');
});

Route::middleware('throttle:' . config('api.rate_limits.access'))
->group(function () {

});
});

0 comments on commit 149ab3a

Please sign in to comment.