Customizable gateway endpoints

This commit is contained in:
2026-01-25 01:27:17 +08:00
parent b851b9f6e2
commit db3a6ea9c5
6 changed files with 160 additions and 7 deletions

View File

@@ -1,10 +1,12 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.RateLimiting;
using DysonNetwork.Gateway.Configuration;
using DysonNetwork.Gateway.Health;
using DysonNetwork.Shared.Networking;
using Yarp.ReverseProxy.Configuration;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Options;
using NodaTime;
using NodaTime.Serialization.SystemTextJson;
@@ -17,6 +19,10 @@ builder.ConfigureAppKestrel(builder.Configuration, maxRequestBodySize: long.MaxV
builder.Services.AddSingleton<GatewayReadinessStore>();
builder.Services.AddHostedService<GatewayHealthAggregator>();
// Add configuration options for gateway endpoints
builder.Services.Configure<DysonNetwork.Gateway.Configuration.GatewayEndpointsOptions>(
builder.Configuration.GetSection(DysonNetwork.Gateway.Configuration.GatewayEndpointsOptions.SectionName));
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
@@ -170,6 +176,15 @@ builder.Services.AddControllers().AddJsonOptions(options =>
var app = builder.Build();
// Initialize GatewayConstant with configuration values
var gatewayEndpointsOptions = app.Services
.GetRequiredService<IOptions<GatewayEndpointsOptions>>().Value;
GatewayConstant.InitializeFromConfiguration(gatewayEndpointsOptions);
// Reinitialize the readiness store with configured service names
var readinessStore = app.Services.GetRequiredService<GatewayReadinessStore>();
readinessStore.ReinitializeServices(GatewayConstant.ServiceNames);
var forwardedHeadersOptions = new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.All
@@ -186,4 +201,4 @@ app.MapReverseProxy().RequireRateLimiting("fixed");
app.MapControllers();
app.Run();
app.Run();