Skip to content

Commit

Permalink
feat: add API settings to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ast21 committed Mar 24, 2023
1 parent 0a5d19d commit e6ebb8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
23 changes: 22 additions & 1 deletion config/porto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,26 @@

// config for AdminKit/Porto
return [
//

'api' => [
'url' => env('API_URL'),
'prefix' => env('API_PREFIX', '/api'),
'enable_version_prefix' => true,

/*
|--------------------------------------------------------------------------
| Rate Limit (throttle)
|--------------------------------------------------------------------------
|
| Attempts per minutes.
| `attempts` is the number of attempts per `expires` in minutes.
|
*/
'throttle' => [
'enabled' => env('GLOBAL_API_RATE_LIMIT_ENABLED', true),
'attempts' => env('GLOBAL_API_RATE_LIMIT_ATTEMPTS_PER_MIN', '30'),
'expires' => env('GLOBAL_API_RATE_LIMIT_EXPIRES_IN_MIN', '1'),
],

],
];
15 changes: 8 additions & 7 deletions src/Loaders/RoutesLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ private function getRateLimitMiddleware(): ?string
{
$rateLimitMiddleware = null;

if (Config::get('apiato.api.throttle.enabled')) {
if (Config::get('porto.api.throttle.enabled')) {
RateLimiter::for('api', function (Request $request) {
return Limit::perMinutes(
Config::get('apiato.api.throttle.expires'),
Config::get('apiato.api.throttle.attempts')
Config::get('porto.api.throttle.expires'),
Config::get('porto.api.throttle.attempts')
)->by($request->user()?->id ?: $request->ip());
});

Expand All @@ -107,14 +107,15 @@ private function getRateLimitMiddleware(): ?string
*/
private function getApiUrl()
{
return Config::get('apiato.api.url');
return Config::get('porto.api.url');
}

private function getApiVersionPrefix($file): string
{
return Config::get('apiato.api.prefix').(Config::get(
'apiato.api.enable_version_prefix'
) ? $this->getRouteFileVersionFromFileName($file) : '');
$prefix = trim(config('porto.api.prefix'), " /\t\n\r\0\x0B");
$version = config('porto.api.enable_version_prefix') ? $this->getRouteFileVersionFromFileName($file) : '';

return $prefix.'/'.$version;
}

private function getRouteFileVersionFromFileName($file): string|bool
Expand Down

0 comments on commit e6ebb8d

Please sign in to comment.