From fd11ef9005b5460eb20fec3c142a8548f0d0570a Mon Sep 17 00:00:00 2001 From: dmolinari Date: Tue, 24 Jun 2025 20:51:57 -0300 Subject: [PATCH] =?UTF-8?q?Se=20a=C3=B1ade=20servicio=20de=20HealtCheck=20?= =?UTF-8?q?de=20SqlServer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se pretende utilizar mediante Kuma --- .../GestionIntegral.Api.csproj | 1 + Backend/GestionIntegral.Api/Program.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Backend/GestionIntegral.Api/GestionIntegral.Api.csproj b/Backend/GestionIntegral.Api/GestionIntegral.Api.csproj index 8c4e0df..91aad60 100644 --- a/Backend/GestionIntegral.Api/GestionIntegral.Api.csproj +++ b/Backend/GestionIntegral.Api/GestionIntegral.Api.csproj @@ -7,6 +7,7 @@ + diff --git a/Backend/GestionIntegral.Api/Program.cs b/Backend/GestionIntegral.Api/Program.cs index 142c51f..ff613b4 100644 --- a/Backend/GestionIntegral.Api/Program.cs +++ b/Backend/GestionIntegral.Api/Program.cs @@ -16,6 +16,7 @@ using Microsoft.OpenApi.Models; using GestionIntegral.Api.Data.Repositories.Reportes; using GestionIntegral.Api.Services.Reportes; using GestionIntegral.Api.Services.Pdf; +using Microsoft.Extensions.Diagnostics.HealthChecks; var builder = WebApplication.CreateBuilder(args); @@ -96,6 +97,18 @@ builder.Services.AddScoped(); // QuestPDF builder.Services.AddScoped(); +// --- SERVICIO DE HEALTH CHECKS --- +// Añadimos una comprobación específica para SQL Server. +// El sistema usará la cadena de conexión configurada en appsettings.json o variables de entorno. +builder.Services.AddHealthChecks() + .AddSqlServer( + connectionString: builder.Configuration.GetConnectionString("DefaultConnection") ?? "", + healthQuery: "SELECT 1;", + name: "sql-server", + failureStatus: HealthStatus.Unhealthy, + tags: new string[] { "database" } + ); + // --- Configuración de Autenticación JWT --- var jwtSettings = builder.Configuration.GetSection("Jwt"); @@ -226,6 +239,10 @@ app.UseCors(MyAllowSpecificOrigins); app.UseAuthentication(); // Debe ir ANTES de UseAuthorization app.UseAuthorization(); +// Mapeamos la ruta "/health". Cuando se acceda a ella, se ejecutarán todas las comprobaciones registradas. +// Esto va ANTES de app.MapControllers(). +app.MapHealthChecks("/health"); + app.MapControllers(); app.Run(); \ No newline at end of file