48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Text.Json;
|
|
using Backend.Data;
|
|
using Backend.Gateway;
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
builder.Services.AddHealthChecks();
|
|
builder.Services.AddProblemDetails();
|
|
|
|
builder.Services.AddApiGateway(builder.Configuration);
|
|
builder.Services.AddPersistence(builder.Configuration);
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseExceptionHandler();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseApiGateway();
|
|
|
|
app.MapHealthChecks(ApiRoutes.Health, new HealthCheckOptions
|
|
{
|
|
ResponseWriter = async (context, report) =>
|
|
{
|
|
context.Response.ContentType = "application/json";
|
|
var payload = JsonSerializer.Serialize(new
|
|
{
|
|
status = report.Status == HealthStatus.Healthy ? "healthy" : "unhealthy",
|
|
});
|
|
await context.Response.WriteAsync(payload);
|
|
},
|
|
});
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|