]> BookStack Code Mirror - bookstack/blob - app/Providers/RouteServiceProvider.php
Fixed failing test after drawio default url change
[bookstack] / app / Providers / RouteServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
5 use Illuminate\Cache\RateLimiting\Limit;
6 use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\RateLimiter;
9 use Illuminate\Support\Facades\Route;
10
11 class RouteServiceProvider extends ServiceProvider
12 {
13     /**
14      * The path to the "home" route for your application.
15      *
16      * This is used by Laravel authentication to redirect users after login.
17      *
18      * @var string
19      */
20     public const HOME = '/';
21
22     /**
23      * This namespace is applied to the controller routes in your routes file.
24      *
25      * In addition, it is set as the URL generator's root namespace.
26      *
27      * @var string
28      */
29
30     /**
31      * Define your route model bindings, pattern filters, etc.
32      *
33      * @return void
34      */
35     public function boot()
36     {
37         $this->configureRateLimiting();
38
39         $this->routes(function () {
40             $this->mapWebRoutes();
41             $this->mapApiRoutes();
42         });
43     }
44
45     /**
46      * Define the "web" routes for the application.
47      *
48      * These routes all receive session state, CSRF protection, etc.
49      *
50      * @return void
51      */
52     protected function mapWebRoutes()
53     {
54         Route::group([
55             'middleware' => 'web',
56             'namespace'  => $this->namespace,
57         ], function ($router) {
58             require base_path('routes/web.php');
59         });
60     }
61
62     /**
63      * Define the "api" routes for the application.
64      *
65      * These routes are typically stateless.
66      *
67      * @return void
68      */
69     protected function mapApiRoutes()
70     {
71         Route::group([
72             'middleware' => 'api',
73             'namespace'  => $this->namespace . '\Api',
74             'prefix'     => 'api',
75         ], function ($router) {
76             require base_path('routes/api.php');
77         });
78     }
79
80     /**
81      * Configure the rate limiters for the application.
82      *
83      * @return void
84      */
85     protected function configureRateLimiting()
86     {
87         RateLimiter::for('api', function (Request $request) {
88             return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
89         });
90     }
91 }