X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b94b945fb03e21a1997cfe6e50148967586cb26d..refs/pull/3918/head:/app/Providers/RouteServiceProvider.php diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index a37780e52..415ec6626 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,19 +2,22 @@ namespace BookStack\Providers; +use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; -use Route; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\RateLimiter; +use Illuminate\Support\Facades\Route; class RouteServiceProvider extends ServiceProvider { /** - * This namespace is applied to the controller routes in your routes file. + * The path to the "home" route for your application. * - * In addition, it is set as the URL generator's root namespace. + * This is used by Laravel authentication to redirect users after login. * * @var string */ - protected $namespace = 'BookStack\Http\Controllers'; + public const HOME = '/'; /** * Define your route model bindings, pattern filters, etc. @@ -23,19 +26,14 @@ class RouteServiceProvider extends ServiceProvider */ public function boot() { - parent::boot(); - } + $this->configureRateLimiting(); - /** - * Define the routes for the application. - * - * @return void - */ - public function map() - { - $this->mapWebRoutes(); - $this->mapApiRoutes(); + $this->routes(function () { + $this->mapWebRoutes(); + $this->mapApiRoutes(); + }); } + /** * Define the "web" routes for the application. * @@ -47,11 +45,12 @@ class RouteServiceProvider extends ServiceProvider { Route::group([ 'middleware' => 'web', - 'namespace' => $this->namespace, + 'namespace' => $this->namespace, ], function ($router) { require base_path('routes/web.php'); }); } + /** * Define the "api" routes for the application. * @@ -63,10 +62,22 @@ class RouteServiceProvider extends ServiceProvider { Route::group([ 'middleware' => 'api', - 'namespace' => $this->namespace . '\Api', - 'prefix' => 'api', + 'namespace' => $this->namespace . '\Api', + 'prefix' => 'api', ], function ($router) { require base_path('routes/api.php'); }); } + + /** + * Configure the rate limiters for the application. + * + * @return void + */ + protected function configureRateLimiting() + { + RateLimiter::for('api', function (Request $request) { + return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()); + }); + } }