Skip to content

Commit f47a1a4

Browse files
committed
Use HealthChecks
1 parent b39c4d2 commit f47a1a4

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.Extensions.Diagnostics.HealthChecks;
2+
3+
[assembly: HostingStartup(typeof(TechStacks.HealthChecks))]
4+
5+
namespace TechStacks;
6+
7+
public class HealthChecks : IHostingStartup
8+
{
9+
public class HealthCheck : IHealthCheck
10+
{
11+
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token = default)
12+
{
13+
// Perform health check logic here
14+
return HealthCheckResult.Healthy();
15+
}
16+
}
17+
18+
public void Configure(IWebHostBuilder builder)
19+
{
20+
builder.ConfigureServices(services =>
21+
{
22+
services.AddHealthChecks()
23+
.AddCheck<HealthCheck>("HealthCheck");
24+
25+
services.AddTransient<IStartupFilter, StartupFilter>();
26+
});
27+
}
28+
29+
public class StartupFilter : IStartupFilter
30+
{
31+
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
32+
=> app => {
33+
app.UseHealthChecks("/up");
34+
next(app);
35+
};
36+
}
37+
}

TechStacks/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@
164164
return TypedResults.Challenge(properties, ["GitHub"]);
165165
});
166166

167-
app.MapGet("/up", () => Results.Ok("OK"));
168-
169167
app.UseServiceStack(new AppHost(), options =>
170168
{
171169
options.MapEndpoints();

0 commit comments

Comments
 (0)