diff --git a/src/PackageRegistryService/PackageRegistryService.csproj b/src/PackageRegistryService/PackageRegistryService.csproj index ee9e4b5..3bbe39a 100644 --- a/src/PackageRegistryService/PackageRegistryService.csproj +++ b/src/PackageRegistryService/PackageRegistryService.csproj @@ -21,6 +21,8 @@ + + diff --git a/src/PackageRegistryService/Program.cs b/src/PackageRegistryService/Program.cs index 3770453..c2230c7 100644 --- a/src/PackageRegistryService/Program.cs +++ b/src/PackageRegistryService/Program.cs @@ -13,6 +13,9 @@ using PackageRegistryService.API.Endpoints; using PackageRegistryService.Data; using Microsoft.AspNetCore.Http.Json; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using HealthChecks.UI.Client; + // ------------------------- ApplicationBuilder ------------------------- // in this section, we will add the necessary code to configure the application builder, @@ -40,6 +43,7 @@ ) ); + builder.Services.Configure(options => { options.ForwardedHeaders = @@ -48,6 +52,10 @@ builder.Services.Configure(options => options.SerializerOptions.PropertyNamingPolicy = null); +builder.Services.AddHealthChecks() + //.AddCheck("Database"); + .AddNpgSql(builder.Configuration.GetConnectionString("PostgressConnectionString")); + // ------------------------- WebApplication ------------------------- // in this section, we will add the necessary code to configure the WebApplication, // which defines the HTTP request pipeline. @@ -83,6 +91,12 @@ } +app.MapHealthChecks("/_health", new HealthCheckOptions +{ + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse +}); + //.RequireHost(); // use host of status page here to limit this endpoint + // Configure the HTTP request pipeline. // ======================== Packages endpoints =========================