3 namespace BookStack\App\Providers;
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;
14 class RouteServiceProvider extends ServiceProvider
17 * The path to the "home" route for your application.
19 * This is used by Laravel authentication to redirect users after login.
23 public const HOME = '/';
26 * Define your route model bindings, pattern filters, etc.
30 public function boot()
32 $this->configureRateLimiting();
34 $this->routes(function () {
35 $this->mapWebRoutes();
36 $this->mapApiRoutes();
41 * Define the "web" routes for the application.
43 * These routes all receive session state, CSRF protection, etc.
47 protected function mapWebRoutes()
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);
58 'middleware' => ['web', 'auth'],
59 ], function (Router $router) {
60 Theme::dispatch(ThemeEvents::ROUTES_REGISTER_WEB_AUTH, $router);
65 * Define the "api" routes for the application.
67 * These routes are typically stateless.
71 protected function mapApiRoutes()
74 'middleware' => 'api',
75 'namespace' => $this->namespace . '\Api',
77 ], function ($router) {
78 require base_path('routes/api.php');
83 * Configure the rate limiters for the application.
87 protected function configureRateLimiting()
89 RateLimiter::for('api', function (Request $request) {
90 return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());