From 758d4bbe8857d6eb840d7e9633701d673c7beddd Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 7 May 2023 17:53:05 -0700 Subject: [PATCH] Specify routes in config --- .../aggregator/Extensions/Extensions.cs | 19 ++++++------------- .../aggregator/appsettings.json | 12 ++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs index b57429ede..3ed7ca906 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs @@ -5,20 +5,13 @@ internal static class Extensions { public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration) { - // REVIEW: This should come from configuration - var s = new (string, string, string, bool)[] + // REVIEW: We could load the routes and clusters from configuration instead of code + // using YARP's default schema, it's slightly more verbose but also reloable. + var s = new List<(string, string, string, bool)>(); + foreach (var c in configuration.GetRequiredSection("Routes").GetChildren()) { - ("c-short", "c", "catalog", true), - ("c-long", "catalog-api", "catalog", true), - - ("b-short", "b", "basket", true), - ("b-long", "basket-api", "basket", true), - - ("o-short", "o", "orders", true) , - ("o-long", "ordering-api", "orders", true), - - ("h-long", "hub/notificationhub", "signalr", false) - }; + s.Add((c["0"], c["1"], c["2"], c.GetValue("3", false))); + } var routes = new List(); var clusters = new Dictionary(); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json b/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json index f3f1f44c7..729dd5011 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json @@ -27,6 +27,18 @@ "webshoppingagg": "Shopping Aggregator for Web Clients" } }, + "Routes": [ + [ "c-short", "c", "catalog", true ], + [ "c-long", "catalog-api", "catalog", true ], + + [ "b-short", "b", "basket", true ], + [ "b-long", "basket-api", "basket", true ], + + [ "o-short", "o", "orders", true ], + [ "o-long", "ordering-api", "orders", true ], + + [ "h-long", "hub/notificationhub", "signalr", false ] + ], "Urls": { "Basket": "http://localhost:5221", "Catalog": "http://localhost:5222",