Skip to content

Commit a050153

Browse files
authored
feat: make API rate limits configurable via env vars (#1204)
* feat: make API rate limits configurable via env vars
1 parent 9d9731c commit a050153

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ FORWARD_DB_PORT=54329
8787
VITE_HOST_NAME=vite.solidtime.test
8888
VITE_APP_NAME="${APP_NAME}"
8989
#SAIL_XDEBUG_MODE=develop,debug,coverage
90+
91+
# API rate limiting (requests per minute)
92+
API_RATE_LIMIT_AUTH_PER_MINUTE=200
93+
API_RATE_LIMIT_GUEST_PER_MINUTE=60

app/Providers/RouteServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function boot(): void
3333
}
3434

3535
return $request->user()
36-
? Limit::perMinute(200)->by($request->user()->id)
37-
: Limit::perMinute(60)->by($request->ip());
36+
? Limit::perMinute(config('services.api.authenticated'))->by($request->user()->id)
37+
: Limit::perMinute(config('services.api.guest'))->by($request->ip());
3838
});
3939

4040
$this->routes(function (): void {

config/services.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
'basic_auth_username' => env('GOTENBERG_BASIC_AUTH_USERNAME'),
99
'basic_auth_password' => env('GOTENBERG_BASIC_AUTH_PASSWORD'),
1010
],
11+
'api' => [
12+
'authenticated' => (int) env('API_RATE_LIMIT_AUTH_PER_MINUTE', 200),
13+
'guest' => (int) env('API_RATE_LIMIT_GUEST_PER_MINUTE', 60),
14+
],
1115
];

0 commit comments

Comments
 (0)