Skip to content

Commit e95a532

Browse files
committed
Make rate limit configurable; closes pterodactyl#1695
1 parent fde8465 commit e95a532

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

app/Http/Kernel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Kernel extends HttpKernel
6969
RequireTwoFactorAuthentication::class,
7070
],
7171
'api' => [
72-
'throttle:240,1',
7372
IsValidJson::class,
7473
ApiSubstituteBindings::class,
7574
SetSessionDriver::class,
@@ -78,7 +77,6 @@ class Kernel extends HttpKernel
7877
AuthenticateIPAccess::class,
7978
],
8079
'client-api' => [
81-
'throttle:240,1',
8280
StartSession::class,
8381
SetSessionDriver::class,
8482
AuthenticateSession::class,

app/Providers/RouteServiceProvider.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ public function map()
3838
->namespace($this->namespace . '\Server')
3939
->group(base_path('routes/server.php'));
4040

41-
Route::middleware(['api'])->prefix('/api/application')
41+
Route::middleware([
42+
sprintf('throttle:%s,%s', config('http.rate_limit.application'), config('http.rate_limit.application_period')),
43+
'api',
44+
])->prefix('/api/application')
4245
->namespace($this->namespace . '\Api\Application')
4346
->group(base_path('routes/api-application.php'));
4447

45-
Route::middleware(['client-api'])->prefix('/api/client')
48+
Route::middleware([
49+
sprintf('throttle:%s,%s', config('http.rate_limit.client'), config('http.rate_limit.client_period')),
50+
'client-api',
51+
])->prefix('/api/client')
4652
->namespace($this->namespace . '\Api\Client')
4753
->group(base_path('routes/api-client.php'));
4854

config/http.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| API Rate Limits
7+
|--------------------------------------------------------------------------
8+
|
9+
| Defines the rate limit for the number of requests per minute that can be
10+
| executed against both the client and internal (application) APIs over the
11+
| defined period (by default, 1 minute).
12+
|
13+
*/
14+
'rate_limit' => [
15+
'client_period' => 1,
16+
'client' => env('APP_API_CLIENT_RATELIMIT', 240),
17+
18+
'application_period' => 1,
19+
'application' => env('APP_API_APPLICATION_RATELIMIT', 240),
20+
],
21+
];

config/pterodactyl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,7 @@
223223
|
224224
| 'P_SERVER_CREATED_AT' => 'created_at'
225225
*/
226-
'environment_variables' => [],
226+
'environment_variables' => [
227+
'P_SERVER_ALLOCATION_LIMIT' => 'allocation_limit',
228+
],
227229
];

0 commit comments

Comments
 (0)