snipe-it/app/Providers/RouteServiceProvider.php

97 lines
2.9 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Providers;
2021-06-10 13:17:07 -07:00
use Illuminate\Cache\RateLimiting\Limit;
2016-03-25 01:18:05 -07:00
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
2021-06-10 13:19:27 -07:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
2016-03-25 01:18:05 -07:00
class RouteServiceProvider extends ServiceProvider
{
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
2016-12-14 04:32:24 -08:00
public function boot()
2016-03-25 01:18:05 -07:00
{
2021-06-10 13:17:07 -07:00
$this->configureRateLimiting();
2016-03-25 01:18:05 -07:00
2021-06-10 13:17:07 -07:00
$this->routes(function () {
$this->mapApiRoutes();
2016-03-25 01:18:05 -07:00
2021-06-10 13:17:07 -07:00
$this->mapWebRoutes();
2016-12-14 04:32:24 -08:00
require base_path('routes/scim.php');
2021-06-10 13:17:07 -07:00
});
2016-12-14 04:32:24 -08:00
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
// 'namespace' => $this->namespace, //okay, I don't know what this means, but somehow this might be a problem for us?
2016-12-14 04:32:24 -08:00
], function ($router) {
require base_path('routes/web/hardware.php');
2016-12-15 06:11:03 -08:00
require base_path('routes/web/models.php');
require base_path('routes/web/accessories.php');
require base_path('routes/web/licenses.php');
require base_path('routes/web/consumables.php');
require base_path('routes/web/fields.php');
2016-12-15 19:59:42 -08:00
require base_path('routes/web/components.php');
2016-12-15 20:52:39 -08:00
require base_path('routes/web/users.php');
2018-10-19 07:30:25 -07:00
require base_path('routes/web/kits.php');
2016-12-14 04:32:24 -08:00
require base_path('routes/web.php');
});
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::group([
2017-01-11 14:50:38 -08:00
'middleware' => 'auth:api',
// 'namespace' => $this->namespace, // this might also be a problem? I don't really know :/
2016-12-14 04:32:24 -08:00
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
2016-03-25 01:18:05 -07:00
});
}
2021-06-10 13:17:07 -07:00
/**
* Configure the rate limiters for the application.
*
* https://laravel.com/docs/8.x/routing#rate-limiting
*
2021-06-10 13:17:07 -07:00
* @return void
*/
protected function configureRateLimiting()
{
// Rate limiter for API calls
2021-06-10 13:17:07 -07:00
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(config('app.api_throttle_per_minute'))->by(optional($request->user())->id ?: $request->ip());
2021-06-10 13:17:07 -07:00
});
// Rate limiter for forgotten password requests
RateLimiter::for('forgotten_password', function (Request $request) {
return Limit::perMinute(config('auth.password_reset.max_attempts_per_min'))->by(optional($request->user())->id ?: $request->ip());
});
2021-06-10 13:17:07 -07:00
}
2016-03-25 01:18:05 -07:00
}