withRouting( api: __DIR__ . '/../routes/api.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // Register custom middleware aliases $middleware->alias([ 'hmac.auth' => \App\Http\Middleware\HmacAuthMiddleware::class, 'jwt.auth' => \App\Http\Middleware\JwtAuthMiddleware::class, 'admin' => \App\Http\Middleware\AdminMiddleware::class, ]); // Global API middleware $middleware->api(prepend: [ \Illuminate\Http\Middleware\HandleCors::class, 'throttle:120,1', ]); }) ->withExceptions(function (Exceptions $exceptions) { $exceptions->render(function (\Throwable $e, \Illuminate\Http\Request $request) { if ($request->is('api/*')) { \Log::error('API Exception: ' . get_class($e), [ 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), ]); $status = 500; if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface) { $status = $e->getStatusCode(); } elseif ($e instanceof \Illuminate\Validation\ValidationException) { return response()->json([ 'status' => 'failure', 'message' => 'Validation error', 'errors' => $e->errors(), ], 422); } $response = [ 'status' => 'failure', 'message' => $e->getMessage() ?: 'Internal server error', ]; if (config('app.debug')) { $response['exception'] = get_class($e); $response['file'] = $e->getFile(); $response['line'] = $e->getLine(); $response['trace'] = $e->getTrace(); } return response()->json($response, $status); } }); }) ->create() ->useEnvironmentPath('/home/intaleq-api/env');