Skip to content

Instantly share code, notes, and snippets.

@unaizorrilla
Created December 23, 2022 09:15
Show Gist options
  • Save unaizorrilla/b184c4991005a0a01a70718cfc19dbec to your computer and use it in GitHub Desktop.
Save unaizorrilla/b184c4991005a0a01a70718cfc19dbec to your computer and use it in GitHub Desktop.
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddHealthChecks()
.AddUrlGroup(sp =>
{
var uris = new string[]{ "http://www.google.es", "https://www.bing.es" };
var selected = Random.Shared.NextInt64() % 2 == 0 ? uris[0] : uris[1];
return new Uri(selected);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.MapHealthChecks("/ready", new HealthCheckOptions()
{
Predicate = _ => true,
AllowCachingResponses = false,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment