diff --git a/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs b/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs index 9365c64..9b7733d 100644 --- a/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs +++ b/DysonNetwork.Drive/Startup/ApplicationBuilderExtensions.cs @@ -9,11 +9,8 @@ public static class ApplicationBuilderExtensions public static WebApplication ConfigureAppMiddleware(this WebApplication app, ITusStore tusStore) { // Configure the HTTP request pipeline. - if (app.Environment.IsDevelopment()) - { - app.UseSwagger(); - app.UseSwaggerUI(); - } + app.UseSwagger(); + app.UseSwaggerUI(); app.UseAuthorization(); app.MapControllers(); diff --git a/DysonNetwork.Gateway/Program.cs b/DysonNetwork.Gateway/Program.cs index 524047c..c195caf 100644 --- a/DysonNetwork.Gateway/Program.cs +++ b/DysonNetwork.Gateway/Program.cs @@ -32,132 +32,78 @@ builder.Services.AddRateLimiter(options => }); }); -var routes = new[] +var serviceNames = new[] { "ring", "pass", "drive", "sphere", "develop" }; + +var specialRoutes = new[] { - new RouteConfig() + new RouteConfig { RouteId = "ring-ws", ClusterId = "ring", Match = new RouteMatch { Path = "/ws" } }, - new RouteConfig() - { - RouteId = "ring-api", - ClusterId = "ring", - Match = new RouteMatch { Path = "/ring/{**catch-all}" }, - Transforms = - [ - new Dictionary { { "PathRemovePrefix", "/ring" } }, - new Dictionary { { "PathPrefix", "/api" } } - ] - }, - new RouteConfig() + new RouteConfig { RouteId = "pass-openid", ClusterId = "pass", Match = new RouteMatch { Path = "/.well-known/openid-configuration" } }, - new RouteConfig() + new RouteConfig { RouteId = "pass-jwks", ClusterId = "pass", Match = new RouteMatch { Path = "/.well-known/jwks" } }, - new RouteConfig() - { - RouteId = "pass-api", - ClusterId = "pass", - Match = new RouteMatch { Path = "/id/{**catch-all}" }, - Transforms = - [ - new Dictionary { { "PathRemovePrefix", "/id" } }, - new Dictionary { { "PathPrefix", "/api" } } - ] - }, - new RouteConfig() + new RouteConfig { RouteId = "drive-tus", ClusterId = "drive", Match = new RouteMatch { Path = "/api/tus" } - }, - new RouteConfig() - { - RouteId = "drive-api", - ClusterId = "drive", - Match = new RouteMatch { Path = "/drive/{**catch-all}" }, - Transforms = - [ - new Dictionary { { "PathRemovePrefix", "/drive" } }, - new Dictionary { { "PathPrefix", "/api" } } - ] - }, - new RouteConfig() - { - RouteId = "sphere-api", - ClusterId = "sphere", - Match = new RouteMatch { Path = "/sphere/{**catch-all}" }, - Transforms = - [ - new Dictionary { { "PathRemovePrefix", "/sphere" } }, - new Dictionary { { "PathPrefix", "/api" } } - ] - }, - new RouteConfig() - { - RouteId = "develop-api", - ClusterId = "develop", - Match = new RouteMatch { Path = "/develop/{**catch-all}" }, - Transforms = - [ - new Dictionary { { "PathRemovePrefix", "/develop" } }, - new Dictionary { { "PathPrefix", "/api" } } - ] } }; -var clusters = new[] +var apiRoutes = serviceNames.Select(serviceName => { - new ClusterConfig() + var apiPath = serviceName switch { - ClusterId = "ring", - Destinations = new Dictionary - { - { "destination1", new DestinationConfig() { Address = "http://ring" } } - } - }, - new ClusterConfig() + "pass" => "/id", + _ => $"/{serviceName}" + }; + return new RouteConfig { - ClusterId = "pass", - Destinations = new Dictionary - { - { "destination1", new DestinationConfig() { Address = "http://pass" } } - } - }, - new ClusterConfig() + RouteId = $"{serviceName}-api", + ClusterId = serviceName, + Match = new RouteMatch { Path = $"{apiPath}/{{**catch-all}}" }, + Transforms = + [ + new Dictionary { { "PathRemovePrefix", apiPath } }, + new Dictionary { { "PathPrefix", "/api" } } + ] + }; +}); + +var swaggerRoutes = serviceNames.Select(serviceName => new RouteConfig +{ + RouteId = $"{serviceName}-swagger", + ClusterId = serviceName, + Match = new RouteMatch { Path = $"/swagger/{serviceName}/{{**catch-all}}" }, + Transforms = + [ + new Dictionary { { "PathRemovePrefix", $"/swagger/{serviceName}" } }, + new Dictionary { { "PathPrefix", "/swagger" } } + ] +}); + +var routes = specialRoutes.Concat(apiRoutes).Concat(swaggerRoutes).ToArray(); + +var clusters = serviceNames.Select(serviceName => new ClusterConfig +{ + ClusterId = serviceName, + Destinations = new Dictionary { - ClusterId = "drive", - Destinations = new Dictionary - { - { "destination1", new DestinationConfig() { Address = "http://drive" } } - } - }, - new ClusterConfig() - { - ClusterId = "sphere", - Destinations = new Dictionary - { - { "destination1", new DestinationConfig() { Address = "http://sphere" } } - } - }, - new ClusterConfig() - { - ClusterId = "develop", - Destinations = new Dictionary - { - { "destination1", new DestinationConfig() { Address = "http://develop" } } - } + { "destination1", new DestinationConfig { Address = $"http://{serviceName}" } } } -}; +}).ToArray(); builder.Services .AddReverseProxy() diff --git a/DysonNetwork.ServiceDefaults/Extensions.cs b/DysonNetwork.ServiceDefaults/Extensions.cs index 4b8dc80..3a85ee7 100644 --- a/DysonNetwork.ServiceDefaults/Extensions.cs +++ b/DysonNetwork.ServiceDefaults/Extensions.cs @@ -21,7 +21,7 @@ public static class Extensions { // Allow unencrypted grpc AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); - + builder.ConfigureOpenTelemetry(); builder.AddDefaultHealthChecks(); @@ -134,4 +134,4 @@ public static class Extensions return app; } -} \ No newline at end of file +} diff --git a/DysonNetwork.Sphere/Startup/ApplicationConfiguration.cs b/DysonNetwork.Sphere/Startup/ApplicationConfiguration.cs index 81bfa88..63ba5f3 100644 --- a/DysonNetwork.Sphere/Startup/ApplicationConfiguration.cs +++ b/DysonNetwork.Sphere/Startup/ApplicationConfiguration.cs @@ -14,7 +14,7 @@ public static class ApplicationConfiguration app.UseSwagger(); app.UseSwaggerUI(); - + app.UseRequestLocalization(); app.ConfigureForwardedHeaders(configuration);