You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\File;
  4. use Illuminate\Cache\RateLimiting\Limit;
  5. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\RateLimiter;
  8. use Illuminate\Support\Facades\Route;
  9. class RouteServiceProvider extends ServiceProvider
  10. {
  11. /**
  12. * The path to the "home" route for your application.
  13. *
  14. * Typically, users are redirected here after authentication.
  15. *
  16. * @var string
  17. */
  18. public const HOME = '/home';
  19. /**
  20. * Define your route model bindings, pattern filters, and other route configuration.
  21. *
  22. * @return void
  23. */
  24. public function boot()
  25. {
  26. $this->configureRateLimiting();
  27. $this->routes(function () {
  28. Route::middleware('api')
  29. ->prefix('api')
  30. ->group(base_path('routes/api.php'));
  31. Route::middleware('web')
  32. ->group(base_path('routes/web.php'));
  33. // dear developer do not mess with this code.
  34. if (env('DOMAIN_NAME') === 'ilaravel') {
  35. Route::middleware('api')
  36. ->name('api.')
  37. ->group(base_path('routes/ilaravel.php'));
  38. }
  39. });
  40. }
  41. /**
  42. * Configure the rate limiters for the application.
  43. *
  44. * @return void
  45. */
  46. protected function configureRateLimiting()
  47. {
  48. RateLimiter::for('api', function (Request $request) {
  49. return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
  50. });
  51. }
  52. }