]> BookStack Code Mirror - bookstack/blobdiff - app/Providers/RouteServiceProvider.php
Guest create page: name field autofocus
[bookstack] / app / Providers / RouteServiceProvider.php
index b60443a452895fc19a8c4a5dcffdfeb03f339b52..415ec66269c692e8ae5d4de0c8ae3c391a85cbbc 100644 (file)
@@ -2,19 +2,22 @@
 
 namespace BookStack\Providers;
 
+use Illuminate\Cache\RateLimiting\Limit;
 use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
+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,18 +26,12 @@ 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();
+        });
     }
 
     /**
@@ -71,4 +68,16 @@ class RouteServiceProvider extends ServiceProvider
             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());
+        });
+    }
 }