39 lines
1.6 KiB
PHP
39 lines
1.6 KiB
PHP
<?php
|
||
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| 【应用入口】路由与中间件
|
||
|--------------------------------------------------------------------------
|
||
| api 分组 prepend了 NegotiateLotteryLocale:
|
||
| 保证任意 API 在未进入控制器前已确定 lottery_locale / app locale,便于统一翻译 msg。
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
|
||
use Illuminate\Foundation\Application;
|
||
use Illuminate\Foundation\Configuration\Exceptions;
|
||
use Illuminate\Foundation\Configuration\Middleware;
|
||
|
||
return Application::configure(basePath: dirname(__DIR__))
|
||
->withRouting(
|
||
web: __DIR__.'/../routes/web.php',
|
||
// 自动加前缀 `api` + middleware `api`,见 routes/api.php
|
||
api: __DIR__.'/../routes/api.php',
|
||
commands: __DIR__.'/../routes/console.php',
|
||
health: '/up',
|
||
)
|
||
->withMiddleware(function (Middleware $middleware): void {
|
||
// 多语言:必须在其他 api 中间件之前执行,以便鉴权失败时也能按语言返回 msg
|
||
$middleware->api(prepend: [
|
||
\App\Http\Middleware\NegotiateLotteryLocale::class,
|
||
]);
|
||
$middleware->alias([
|
||
// 玩家端需登录路由使用;解析 Bearer → Player
|
||
'lottery.player' => \App\Http\Middleware\EnsurePlayerApi::class,
|
||
// 后台 API 预留:Sanctum / RBAC
|
||
'lottery.admin' => \App\Http\Middleware\EnsureAdminApi::class,
|
||
]);
|
||
})
|
||
->withExceptions(function (Exceptions $exceptions): void {
|
||
//
|
||
})->create();
|