Skip to content

Commit

Permalink
remove rate limiter for api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Dec 9, 2023
1 parent a870a4b commit c76f36e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace Convoy\Providers;

use Convoy\Models\Server;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Convoy\Http\Middleware\AdminAuthenticate;
use Convoy\Http\Middleware\Coterm\CotermAuthenticate;
use Convoy\Models\Server;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
Expand All @@ -28,40 +25,37 @@ class RouteServiceProvider extends ServiceProvider
public function boot(): void
{
Route::bind('server', function ($value) {
return Server::query()->where(strlen($value) === 8 ? 'uuid_short' : 'uuid', $value)->firstOrFail();
});

RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
return Server::query()->where(strlen($value) === 8 ? 'uuid_short' : 'uuid', $value)
->firstOrFail();
});

$this->routes(function () {
Route::middleware('web')->group(function () {
Route::middleware('guest')->group(base_path('routes/auth.php'));

Route::middleware(['auth.session'])
->group(base_path('routes/base.php'));
->group(base_path('routes/base.php'));

Route::middleware(['auth'])->prefix('/api/client')
->as('client.')
->group(base_path('routes/api-client.php'));
->as('client.')
->group(base_path('routes/api-client.php'));

Route::middleware(['auth', AdminAuthenticate::class])
->prefix('/api/admin')
->as('admin.')
->group(base_path('routes/api-admin.php'));
->prefix('/api/admin')
->as('admin.')
->group(base_path('routes/api-admin.php'));
});

Route::middleware(['api'])->group(function () {
Route::middleware(['auth:sanctum'])
->prefix('/api/application')
->as('application.')
->group(base_path('routes/api-application.php'));

Route::middleware([CotermAuthenticate::class])
->prefix('/api/coterm')
->as('coterm.')
->group(base_path('routes/api-coterm.php'));
->prefix('/api/application')
->as('application.')
->group(base_path('routes/api-application.php'));

Route::middleware([CotermAuthenticate::class])
->prefix('/api/coterm')
->as('coterm.')
->group(base_path('routes/api-coterm.php'));
});
});
}
Expand Down

0 comments on commit c76f36e

Please sign in to comment.