Skip to content

Commit ba8e936

Browse files
authored
Add health check endpoint (#188)
1 parent d490989 commit ba8e936

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

StartSch/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ await scope.ServiceProvider
215215
// API controllers
216216
builder.Services
217217
.AddControllersWithViews() // WithViews is needed to use the ValidateAntiForgeryToken attribute
218-
.AddJsonOptions(o => o.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
218+
.AddJsonOptions(o => o.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
219+
220+
builder.Services.AddHealthChecks().AddDbContextCheck<Db>();
219221

220222
builder.Services.AddHttpContextAccessor();
221223

@@ -285,6 +287,7 @@ await scope.ServiceProvider
285287
});
286288

287289
app.MapStaticAssets();
290+
app.MapHealthChecks("/healthz");
288291
app.MapControllers();
289292
app.MapRazorComponents<App>()
290293
.AddInteractiveServerRenderMode()

StartSch/StartSch.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="10.0.1" />
2727
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.1" PrivateAssets="all" IncludeAssets="runtime; build; native; analyzers" />
2828
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.1" />
29+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.4" />
2930
<PackageReference Include="NodaTime" Version="3.2.3" />
3031
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.3.0" />
3132
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />

0 commit comments

Comments
 (0)