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.
28 public function boot(): void
30 $this->configureRateLimiting();
32 $this->routes(function () {
33 $this->mapWebRoutes();
34 $this->mapApiRoutes();
39 * Define the "web" routes for the application.
41 * These routes all receive session state, CSRF protection, etc.
43 protected function mapWebRoutes(): void
46 'middleware' => 'web',
47 'namespace' => $this->namespace,
48 ], function (Router $router) {
49 require base_path('routes/web.php');
50 Theme::dispatch(ThemeEvents::ROUTES_REGISTER_WEB, $router);
54 'middleware' => ['web', 'auth'],
55 ], function (Router $router) {
56 Theme::dispatch(ThemeEvents::ROUTES_REGISTER_WEB_AUTH, $router);
61 * Define the "api" routes for the application.
63 * These routes are typically stateless.
65 protected function mapApiRoutes(): void
68 'middleware' => 'api',
69 'namespace' => $this->namespace . '\Api',
71 ], function ($router) {
72 require base_path('routes/api.php');
77 * Configure the rate limiters for the application.
79 protected function configureRateLimiting(): void
81 RateLimiter::for('api', function (Request $request) {
82 return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());