X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/eaa1765c7a68cd671bcb37a666203210bf05d217..refs/pull/3406/head:/app/Providers/RouteServiceProvider.php diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index dd166525a..ac3307f2d 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -1,12 +1,24 @@ configureRateLimiting(); - parent::boot($router); + $this->routes(function () { + $this->mapWebRoutes(); + $this->mapApiRoutes(); + }); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + * + * @return void + */ + protected function mapWebRoutes() + { + Route::group([ + 'middleware' => 'web', + 'namespace' => $this->namespace, + ], function ($router) { + require base_path('routes/web.php'); + }); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + * + * @return void + */ + protected function mapApiRoutes() + { + Route::group([ + 'middleware' => 'api', + 'namespace' => $this->namespace . '\Api', + 'prefix' => 'api', + ], function ($router) { + require base_path('routes/api.php'); + }); } /** - * Define the routes for the application. + * Configure the rate limiters for the application. * - * @param \Illuminate\Routing\Router $router * @return void */ - public function map(Router $router) + protected function configureRateLimiting() { - $router->group(['namespace' => $this->namespace], function ($router) { - require app_path('Http/routes.php'); + RateLimiter::for('api', function (Request $request) { + return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()); }); } }