- Created ExampleTest and RoutesTest for basic application response and route testing. - Implemented IsolatedDatabaseTestCase for isolated database testing. - Added unit tests for various models and services including Contract, CPE, and LeadDetail. - Developed request validation tests for CreateClientRequest, UpdateClientRequest, and ContractRequest. - Introduced Vite configuration for asset management in the Laravel application.
80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
web: __DIR__.'/../routes/web.php',
|
|
api: __DIR__.'/../routes/api.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withMiddleware(function (Middleware $middleware) {
|
|
|
|
$middleware->api(prepend: [\App\Http\Middleware\ApiResponse::class]);
|
|
|
|
# Register Middleware
|
|
$middleware->alias([
|
|
'auth.session' => \App\Http\Middleware\AuthSession::class,
|
|
]);
|
|
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions) {
|
|
$exceptions->reportable(function (Throwable $e) {
|
|
|
|
});
|
|
|
|
$exceptions->render(function (Throwable $e, $request) {
|
|
if ($request->is('api/*') || $request->expectsJson()) {
|
|
$status = 500;
|
|
$message = $e->getMessage() ?: 'Erro interno do servidor';
|
|
|
|
if ($e instanceof \Illuminate\Validation\ValidationException) {
|
|
return response()->json([
|
|
'message' => 'Erro de validação.',
|
|
'errors' => $e->errors(),
|
|
], 422);
|
|
}
|
|
|
|
if ($e instanceof \Illuminate\Auth\AuthenticationException) {
|
|
return response()->json(['message' => 'Nao autenticado.'], 401);
|
|
}
|
|
|
|
if ($e instanceof \Illuminate\Auth\Access\AuthorizationException) {
|
|
return response()->json(['message' => 'Acesso negado.'], 403);
|
|
}
|
|
|
|
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
|
|
return response()->json(['message' => 'Registo nao encontrado.'], 404);
|
|
}
|
|
|
|
if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface) {
|
|
$status = $e->getStatusCode();
|
|
$message = $e->getMessage() ?: 'Erro HTTP';
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => $status >= 500 && app()->environment('production') ? 'Erro interno do servidor.' : $message,
|
|
'exception' => app()->environment('production') ? null : get_class($e),
|
|
], $status);
|
|
}
|
|
|
|
return null;
|
|
});
|
|
})
|
|
->withSchedule(function (Schedule $schedule) {
|
|
// $schedule->command('backup:run')->dailyAt('13:00');
|
|
// $schedule->command('backup:clean-minio')->dailyAt('13:30');
|
|
$schedule->command('sanctum:prune-expired --hours=24')->dailyAt('05:00');
|
|
})
|
|
->booted(function () {
|
|
if (config('app.force_ssl')) {
|
|
URL::forceScheme('https');
|
|
}
|
|
})
|
|
->create();
|