Gateway config serving

This commit is contained in:
2025-10-03 16:37:51 +08:00
parent fa24f14c05
commit 8e3e3f09df
3 changed files with 25 additions and 5 deletions

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("config")]
public class ConfigurationController(IConfiguration configuration) : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok(configuration.GetSection("Client").Get<Dictionary<string, object>>());
[HttpGet("site")]
public IActionResult GetSiteUrl() => Ok(configuration["SiteUrl"]);
}

View File

@@ -87,7 +87,7 @@ var swaggerRoutes = serviceNames.Select(serviceName => new RouteConfig
RouteId = $"{serviceName}-swagger", RouteId = $"{serviceName}-swagger",
ClusterId = serviceName, ClusterId = serviceName,
Match = new RouteMatch { Path = $"/swagger/{serviceName}/{{**catch-all}}" }, Match = new RouteMatch { Path = $"/swagger/{serviceName}/{{**catch-all}}" },
Transforms = Transforms =
[ [
new Dictionary<string, string> { { "PathRemovePrefix", $"/swagger/{serviceName}" } }, new Dictionary<string, string> { { "PathRemovePrefix", $"/swagger/{serviceName}" } },
new Dictionary<string, string> { { "PathPrefix", "/swagger" } } new Dictionary<string, string> { { "PathPrefix", "/swagger" } }
@@ -106,9 +106,11 @@ var clusters = serviceNames.Select(serviceName => new ClusterConfig
}).ToArray(); }).ToArray();
builder.Services builder.Services
.AddReverseProxy() .AddReverseProxy()
.LoadFromMemory(routes, clusters) .LoadFromMemory(routes, clusters)
.AddServiceDiscoveryDestinationResolver(); .AddServiceDiscoveryDestinationResolver();
builder.Services.AddControllers();
var app = builder.Build(); var app = builder.Build();
@@ -118,4 +120,6 @@ app.UseRateLimiter();
app.MapReverseProxy().RequireRateLimiting("fixed"); app.MapReverseProxy().RequireRateLimiting("fixed");
app.MapControllers();
app.Run(); app.Run();

View File

@@ -5,5 +5,9 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"SiteUrl": "http://localhost:3000",
"Client": {
"SomeSetting": "SomeValue"
}
} }