49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using MxGateway.Contracts;
|
|
using MxGateway.Server.Configuration;
|
|
using MxGateway.Server.Diagnostics;
|
|
using MxGateway.Server.Metrics;
|
|
using MxGateway.Server.Security.Authentication;
|
|
|
|
namespace MxGateway.Server;
|
|
|
|
public static class GatewayApplication
|
|
{
|
|
public static WebApplication Build(string[] args)
|
|
{
|
|
WebApplicationBuilder builder = CreateBuilder(args);
|
|
WebApplication app = builder.Build();
|
|
|
|
app.UseGatewayRequestLoggingScope();
|
|
app.MapGatewayEndpoints();
|
|
|
|
return app;
|
|
}
|
|
|
|
public static WebApplicationBuilder CreateBuilder(string[] args)
|
|
{
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddGatewayConfiguration();
|
|
builder.Services.AddSqliteAuthStore();
|
|
builder.Services.AddHealthChecks();
|
|
builder.Services.AddSingleton<GatewayMetrics>();
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static IEndpointRouteBuilder MapGatewayEndpoints(this IEndpointRouteBuilder endpoints)
|
|
{
|
|
endpoints.MapGet("/", () => Results.Redirect("/health/live"));
|
|
|
|
endpoints.MapGet(
|
|
"/health/live",
|
|
() => Results.Ok(new GatewayHealthReply(
|
|
Status: "Healthy",
|
|
DefaultBackend: GatewayContractInfo.DefaultBackendName,
|
|
WorkerProtocolVersion: GatewayContractInfo.WorkerProtocolVersion)))
|
|
.WithName("LiveHealth");
|
|
|
|
return endpoints;
|
|
}
|
|
}
|