| <?php |
|
|
| use App\Exceptions\RagApiException; |
| use App\Http\Middleware\EnsureRagAuthenticated; |
| use App\Http\Middleware\HandleAppearance; |
| use App\Http\Middleware\HandleInertiaRequests; |
| use Illuminate\Foundation\Application; |
| use Illuminate\Foundation\Configuration\Exceptions; |
| use Illuminate\Foundation\Configuration\Middleware; |
| use Illuminate\Http\Client\ConnectionException; |
| use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets; |
| use Illuminate\Http\Request; |
| use Inertia\Inertia; |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
|
| return Application::configure(basePath: dirname(__DIR__)) |
| ->withRouting( |
| web: __DIR__.'/../routes/web.php', |
| commands: __DIR__.'/../routes/console.php', |
| health: '/up', |
| ) |
| ->withMiddleware(function (Middleware $middleware): void { |
| $middleware->trustProxies(at: '*'); |
|
|
| $middleware->alias([ |
| 'rag.auth' => EnsureRagAuthenticated::class, |
| ]); |
|
|
| $middleware->encryptCookies(except: [ |
| 'appearance', |
| 'sevima_raghub_auth_token', |
| 'sevima_raghub_auth_user', |
| 'sevima_raghub_embed_token', |
| 'sevima_raghub_embed_user', |
| 'sidebar_state', |
| ]); |
|
|
| $middleware->preventRequestForgery(except: [ |
| 'embed/*', |
| ]); |
|
|
| $middleware->web(append: [ |
| HandleAppearance::class, |
| HandleInertiaRequests::class, |
| AddLinkHeadersForPreloadedAssets::class, |
| ]); |
| }) |
| ->withExceptions(function (Exceptions $exceptions): void { |
| $exceptions->renderable(function (RagApiException $exception, Request $request) { |
| if ($exception->statusCode !== 401) { |
| return null; |
| } |
|
|
| $loginRoute = $request->is('admin*') ? 'admin.login' : 'login'; |
|
|
| return redirect()->route($loginRoute) |
| ->with('status', 'Sesi Anda telah berakhir. Silakan login kembali.') |
| ->withoutCookie('sevima_raghub_auth_token') |
| ->withoutCookie('sevima_raghub_auth_user'); |
| }); |
|
|
| $exceptions->renderable(function (NotFoundHttpException $_, Request $request) { |
| return Inertia::render('error', [ |
| 'status' => 404, |
| ])->toResponse($request)->setStatusCode(404); |
| }); |
|
|
| $exceptions->renderable(function (ConnectionException $exception, Request $request) { |
| if ($request->expectsJson() || $request->header('X-Inertia')) { |
| return response()->json([ |
| 'message' => 'Server tidak bisa dihubungi. Silakan coba lagi.', |
| ], 503); |
| } |
|
|
| return Inertia::render('error', [ |
| 'status' => 503, |
| 'message' => 'Server tidak bisa dihubungi. Silakan coba lagi.', |
| ])->toResponse($request)->setStatusCode(503); |
| }); |
| })->create(); |
|
|