diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs index d1ead0af6..feb217502 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Extensions/Extensions.cs @@ -1,5 +1,69 @@ -internal static class Extensions +using Yarp.ReverseProxy.Configuration; +using Yarp.ReverseProxy.Transforms; + +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)[] + { + ("c-short", "c", "catalog"), + ("c-long", "catalog-api", "catalog"), + + ("b-short", "b", "basket"), + ("b-long", "basket-api", "basket"), + + ("o-short", "o", "orders"), + ("o-long", "ordering-api", "orders"), + + ("h-long", "hub/notificationhub", "signalr") + }; + + var routes = new List(); + var clusters = new Dictionary(); + var urls = configuration.GetRequiredSection("Urls"); + + foreach (var (routeId, prefix, clusterId) in s) + { + var destination = urls.GetRequiredValue(clusterId); + + routes.Add(new() + { + RouteId = routeId, + ClusterId = clusterId, + Match = new() + { + Path = $"/{prefix}/{{**catch-all}}" + }, + Metadata = new Dictionary() + { + ["prefix"] = prefix + } + }); + + clusters[clusterId] = new() + { + ClusterId = clusterId, + Destinations = new Dictionary() + { + { clusterId, new DestinationConfig() { Address = destination } } + } + }; + } + + services.AddReverseProxy().LoadFromMemory(routes, clusters.Values.ToList()) + .AddTransforms(builder => + { + if (builder.Route?.Metadata?["prefix"] is string prefix) + { + builder.AddPathRemovePrefix($"/{prefix}"); + } + }); + + return services; + } + public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration) { services.AddHealthChecks() diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs index 880d9b921..647fb422d 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs @@ -2,6 +2,7 @@ builder.AddServiceDefaults(); +builder.Services.AddReverseProxy(builder.Configuration); builder.Services.AddControllers(); builder.Services.AddHealthChecks(builder.Configuration); @@ -33,5 +34,6 @@ app.UseAuthorization(); app.MapGet("/", () => Results.Redirect("/swagger")); app.MapControllers().RequireCors("CorsPolicy"); +app.MapReverseProxy(); await app.RunAsync(); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj index f5156ca94..d7523af19 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj @@ -8,6 +8,7 @@ + diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json b/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json index cd51126df..f3f1f44c7 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/appsettings.json @@ -32,6 +32,7 @@ "Catalog": "http://localhost:5222", "Orders": "http://localhost:5224", "Identity": "http://localhost:5223", + "Signalr": "http://localhost:5225", "GrpcBasket": "http://localhost:6221", "GrpcCatalog": "http://localhost:6222", "GrpcOrdering": "http://localhost:6224" diff --git a/src/ApiGateways/Yarp/ApiGateway/ApiGateway.csproj b/src/ApiGateways/Yarp/ApiGateway/ApiGateway.csproj deleted file mode 100644 index 432df38e3..000000000 --- a/src/ApiGateways/Yarp/ApiGateway/ApiGateway.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net7.0 - enable - enable - - - - - - - - - - - diff --git a/src/ApiGateways/Yarp/ApiGateway/Program.cs b/src/ApiGateways/Yarp/ApiGateway/Program.cs deleted file mode 100644 index acc40633e..000000000 --- a/src/ApiGateways/Yarp/ApiGateway/Program.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Services.Common; -using Yarp.ReverseProxy.Configuration; -using Yarp.ReverseProxy.Transforms; - -var builder = WebApplication.CreateBuilder(args); - -builder.AddServiceDefaults(); - -var services = new (string, string, string)[] -{ - ("c-short", "c", "catalog"), - ("c-long", "catalog-api", "catalog"), - - ("b-short", "b", "basket"), - ("b-long", "basket-api", "basket"), - - ("o-short", "o", "orders"), - ("o-long", "ordering-api", "orders"), - - ("h-long", "hub/notificationhub", "signalr") -}; - -var routes = new List(); -var clusters = new Dictionary(); -var urls = builder.Configuration.GetRequiredSection("Urls"); - -foreach (var (routeId, prefix, clusterId) in services) -{ - var destination = urls.GetRequiredValue(clusterId); - - routes.Add(new() - { - RouteId = routeId, - ClusterId = clusterId, - Match = new() - { - Path = $"/{prefix}/{{**catch-all}}" - }, - Metadata = new Dictionary() - { - ["prefix"] = prefix - } - }); - - clusters[clusterId] = new() - { - ClusterId = clusterId, - Destinations = new Dictionary() - { - { clusterId, new DestinationConfig() { Address = destination } } - } - }; -} - -builder.Services.AddReverseProxy() - .LoadFromMemory(routes, clusters.Values.ToList()) - .AddTransforms(builder => - { - if (builder.Route?.Metadata?["prefix"] is string prefix) - { - builder.AddPathRemovePrefix($"/{prefix}"); - } - }); - -var app = builder.Build(); - -app.UseServiceDefaults(); - -app.MapReverseProxy(); - -app.Run(); diff --git a/src/ApiGateways/Yarp/ApiGateway/Properties/launchSettings.json b/src/ApiGateways/Yarp/ApiGateway/Properties/launchSettings.json deleted file mode 100644 index 4ebe30168..000000000 --- a/src/ApiGateways/Yarp/ApiGateway/Properties/launchSettings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "profiles": { - "Gateway.Http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "http://localhost:5291", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Gateway.Https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "https://localhost:7132;http://localhost:5291", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/src/ApiGateways/Yarp/ApiGateway/appsettings.Development.json b/src/ApiGateways/Yarp/ApiGateway/appsettings.Development.json deleted file mode 100644 index 0c208ae91..000000000 --- a/src/ApiGateways/Yarp/ApiGateway/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/src/ApiGateways/Yarp/ApiGateway/appsettings.json b/src/ApiGateways/Yarp/ApiGateway/appsettings.json deleted file mode 100644 index 61ff2f8b7..000000000 --- a/src/ApiGateways/Yarp/ApiGateway/appsettings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*", - "Urls": { - "Basket": "http://localhost:5221", - "Catalog": "http://localhost:5222", - "Orders": "http://localhost:5224", - "Identity": "http://localhost:5223", - "Signalr": "http://localhost:5225" - } -} diff --git a/src/Web/WebMVC/appsettings.json b/src/Web/WebMVC/appsettings.json index 401ef7d8f..12c8e251b 100644 --- a/src/Web/WebMVC/appsettings.json +++ b/src/Web/WebMVC/appsettings.json @@ -1,5 +1,5 @@ { - "PurchaseUrl": "http://localhost:5291", + "PurchaseUrl": "http://localhost:5229", "IdentityUrl": "http://localhost:5223", "IdentityUrlHC": "http://localhost:5223/hc", "CallBackUrl": "http://localhost:5100/", diff --git a/src/eShopOnContainers-ServicesAndWebApps.sln b/src/eShopOnContainers-ServicesAndWebApps.sln index b3467e5eb..203d5b54d 100644 --- a/src/eShopOnContainers-ServicesAndWebApps.sln +++ b/src/eShopOnContainers-ServicesAndWebApps.sln @@ -126,10 +126,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services.Common", "Services EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{42B85D0F-2ED6-4C00-91FA-103DACC3D5E2}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Yarp", "Yarp", "{63F5F157-504F-4CE8-86B7-0A6F087BD888}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiGateway", "ApiGateways\Yarp\ApiGateway\ApiGateway.csproj", "{98C6B254-E9D0-4401-BF7A-89E87A38B87E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -1536,54 +1532,6 @@ Global {CD430CE4-D5E0-4C96-84F5-AEC9162651B5}.Release|x64.Build.0 = Release|Any CPU {CD430CE4-D5E0-4C96-84F5-AEC9162651B5}.Release|x86.ActiveCfg = Release|Any CPU {CD430CE4-D5E0-4C96-84F5-AEC9162651B5}.Release|x86.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|x64.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Ad-Hoc|x86.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|Any CPU.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|ARM.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|ARM.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|iPhone.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|x64.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|x64.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|x86.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.AppStore|x86.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|ARM.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|ARM.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|iPhone.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|x64.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|x64.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|x86.ActiveCfg = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Debug|x86.Build.0 = Debug|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|Any CPU.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|ARM.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|ARM.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|iPhone.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|iPhone.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|x64.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|x64.Build.0 = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|x86.ActiveCfg = Release|Any CPU - {98C6B254-E9D0-4401-BF7A-89E87A38B87E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1642,8 +1590,6 @@ Global {95D735BE-2899-4495-BE3F-2600E93B4E3C} = {373D8AA1-36BE-49EC-89F0-6CB736666285} {CD430CE4-D5E0-4C96-84F5-AEC9162651B5} = {42B85D0F-2ED6-4C00-91FA-103DACC3D5E2} {42B85D0F-2ED6-4C00-91FA-103DACC3D5E2} = {91CF7717-08AB-4E65-B10E-0B426F01E2E8} - {63F5F157-504F-4CE8-86B7-0A6F087BD888} = {77849D35-37D4-4802-81DC-9477B2775A40} - {98C6B254-E9D0-4401-BF7A-89E87A38B87E} = {63F5F157-504F-4CE8-86B7-0A6F087BD888} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9}