mdhub/app/application/bootstrap/app.php

55 lines
2.0 KiB
PHP
Raw Normal View History

2024-06-18 22:35:54 +05:00
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
2024-06-18 22:35:54 +05:00
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
commands: __DIR__.'/../routes/console.php',
using: function () {
Route::middleware(['web', \App\Http\Middleware\UserLocale::class])
->group(base_path('routes/web.php'));
Route::middleware(['web', 'auth', 'verified', \App\Http\Middleware\UserIsActive::class, \App\Http\Middleware\AdminPanel::class, \App\Http\Middleware\UserLocale::class])
->prefix('admin')
->as('admin.')
->group(base_path('routes/admin.php'));
Route::middleware(['api'])
->prefix('registry')
->name('registry.')
->group(base_path('routes/registry.php'));
2024-06-18 22:35:54 +05:00
},
)
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'/registry/v2/event',
'/registry/v2/event/*',
]);
2024-06-18 22:35:54 +05:00
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->renderable(function (\Illuminate\Auth\AuthenticationException $e, Request $request) {
if ($request->is('registry/*')) {
return \response()->json([
'message' => $e->getMessage(),
], \Illuminate\Http\Response::HTTP_UNAUTHORIZED);
}
return false;
});
$exceptions->renderable(function (\Illuminate\Http\Exceptions\HttpResponseException $e, Request $request) {
if ($request->is('registry/*')) {
return \response()->json([
'message' => $e->getResponse()->getContent(),
], $e->getResponse()->getStatusCode());
}
return false;
});
2024-06-18 22:35:54 +05:00
})->create();