]> BookStack Code Mirror - bookstack/blob - app/Providers/RouteServiceProvider.php
Added force option for update-url command
[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      * Define your route model bindings, pattern filters, etc.
24      *
25      * @return void
26      */
27     public function boot()
28     {
29         $this->configureRateLimiting();
30
31         $this->routes(function () {
32             $this->mapWebRoutes();
33             $this->mapApiRoutes();
34         });
35     }
36
37     /**
38      * Define the "web" routes for the application.
39      *
40      * These routes all receive session state, CSRF protection, etc.
41      *
42      * @return void
43      */
44     protected function mapWebRoutes()
45     {
46         Route::group([
47             'middleware' => 'web',
48             'namespace'  => $this->namespace,
49         ], function ($router) {
50             require base_path('routes/web.php');
51         });
52     }
53
54     /**
55      * Define the "api" routes for the application.
56      *
57      * These routes are typically stateless.
58      *
59      * @return void
60      */
61     protected function mapApiRoutes()
62     {
63         Route::group([
64             'middleware' => 'api',
65             'namespace'  => $this->namespace . '\Api',
66             'prefix'     => 'api',
67         ], function ($router) {
68             require base_path('routes/api.php');
69         });
70     }
71
72     /**
73      * Configure the rate limiters for the application.
74      *
75      * @return void
76      */
77     protected function configureRateLimiting()
78     {
79         RateLimiter::for('api', function (Request $request) {
80             return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
81         });
82     }
83 }