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