123
This commit is contained in:
33
code/app/api/config/router.php
Normal file
33
code/app/api/config/router.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use app\api\controller\Novel;
|
||||
use app\api\controller\Statis;
|
||||
use think\facade\Route;
|
||||
|
||||
|
||||
Route::post("/publish", [Statis::class, 'publish'])
|
||||
// ->middleware(\think\middleware\Throttle::class, [
|
||||
// 'visit_rate' => '1/m',
|
||||
// 'key' => '__CONTROLLER__/__ACTION__/__IP__',
|
||||
// ])
|
||||
->name('Statis@publish');
|
||||
|
||||
|
||||
Route::get("/search", [Novel::class, 'search'])
|
||||
// ->middleware(\think\middleware\Throttle::class, [
|
||||
// 'visit_rate' => '1/m',
|
||||
// 'key' => '__CONTROLLER__/__ACTION__/__IP__',
|
||||
// ])
|
||||
->name('Novel@search');;
|
||||
|
||||
|
||||
|
||||
|
||||
Route::get("/test", [Statis::class, 'test'])
|
||||
// ->middleware(\think\middleware\Throttle::class, [
|
||||
// 'visit_rate' => '1/m',
|
||||
// 'key' => '__CONTROLLER__/__ACTION__/__IP__',
|
||||
// ])
|
||||
->name('Statis@test');
|
||||
12
code/app/api/config/throttle.php
Normal file
12
code/app/api/config/throttle.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use think\middleware\Throttle;
|
||||
use think\Response;
|
||||
|
||||
return [
|
||||
'prefix' => 'api:throttle_',
|
||||
'visit_method' => ["GET", "POST", "PUT", "DELETE", "HEAD"],
|
||||
'visit_fail_response' => function (Throttle $throttle, $request, $wait_seconds) {
|
||||
return Response::create('抱歉,请求过于频繁, 请 ' . $wait_seconds . ' 秒后重新操作 。')->code(429);
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user