Files
nexusphp/app/Providers/RouteServiceProvider.php

79 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2021-04-02 19:48:41 +08:00
<?php
namespace App\Providers;
use App\Http\Middleware\Filament;
2021-04-02 19:48:41 +08:00
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
2025-03-29 14:32:31 +07:00
Route::prefix('api/v1')
2025-10-14 14:54:44 +07:00
->middleware(['api', 'locale'])
2021-04-02 19:48:41 +08:00
->namespace($this->namespace)
->group(base_path('routes/api.php'));
2025-10-14 14:54:44 +07:00
Route::middleware(['web', 'locale'])
2021-04-02 19:48:41 +08:00
->namespace($this->namespace)
->group(base_path('routes/web.php'));
2022-03-18 15:44:04 +08:00
2023-03-04 23:28:47 +08:00
Route::prefix('api')
->namespace($this->namespace)
->middleware('throttle:third-party')
->group(base_path('routes/third-party.php'));
Route::prefix('admin')
->namespace($this->namespace)
->middleware([Filament::class])
->group(base_path('routes/admin.php'));
2021-04-02 19:48:41 +08:00
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
2023-03-04 23:28:47 +08:00
RateLimiter::for('third-party', function (Request $request) {
return Limit::perMinute(10)->by(getip());
});
2021-04-02 19:48:41 +08:00
}
}