Added YARP as an API gateway
- It will eventually replace envoy
This commit is contained in:
parent
06d74d1658
commit
30ed0011cb
17
src/ApiGateways/Yarp/ApiGateway/ApiGateway.csproj
Normal file
17
src/ApiGateways/Yarp/ApiGateway/ApiGateway.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Yarp.ReverseProxy" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\Services\Services.Common\Services.Common.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
71
src/ApiGateways/Yarp/ApiGateway/Program.cs
Normal file
71
src/ApiGateways/Yarp/ApiGateway/Program.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
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<RouteConfig>();
|
||||||
|
var clusters = new Dictionary<string, ClusterConfig>();
|
||||||
|
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<string, string>()
|
||||||
|
{
|
||||||
|
["prefix"] = prefix
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
clusters[clusterId] = new()
|
||||||
|
{
|
||||||
|
ClusterId = clusterId,
|
||||||
|
Destinations = new Dictionary<string, DestinationConfig>()
|
||||||
|
{
|
||||||
|
{ 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();
|
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/ApiGateways/Yarp/ApiGateway/appsettings.json
Normal file
16
src/ApiGateways/Yarp/ApiGateway/appsettings.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@
|
|||||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="AspNetCore.HealthChecks.AzureServiceBus" Version="6.1.0" />
|
<PackageVersion Include="AspNetCore.HealthChecks.AzureServiceBus" Version="6.1.0" />
|
||||||
<PackageVersion Include="AspNetCore.HealthChecks.AzureStorage" Version="6.1.2" />
|
<PackageVersion Include="AspNetCore.HealthChecks.AzureStorage" Version="6.1.2" />
|
||||||
@ -88,5 +87,6 @@
|
|||||||
<PackageVersion Include="System.Reflection.TypeExtensions" Version="4.7.0" />
|
<PackageVersion Include="System.Reflection.TypeExtensions" Version="4.7.0" />
|
||||||
<PackageVersion Include="xunit" Version="2.4.2" />
|
<PackageVersion Include="xunit" Version="2.4.2" />
|
||||||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
|
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
|
||||||
|
<PackageVersion Include="Yarp.ReverseProxy" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,8 +1,5 @@
|
|||||||
{
|
{
|
||||||
"PurchaseUrl": "http://localhost:5229",
|
"PurchaseUrl": "http://localhost:5291",
|
||||||
"CatalogUrl": "http://localhost:5222",
|
|
||||||
"OrderingUrl": "http://localhost:5224",
|
|
||||||
"BasketUrl": "http://localhost:5221",
|
|
||||||
"IdentityUrl": "http://localhost:5223",
|
"IdentityUrl": "http://localhost:5223",
|
||||||
"IdentityUrlHC": "http://localhost:5223/hc",
|
"IdentityUrlHC": "http://localhost:5223/hc",
|
||||||
"CallBackUrl": "http://localhost:5100/",
|
"CallBackUrl": "http://localhost:5100/",
|
||||||
|
@ -122,10 +122,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{373D8AA1
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.Tests", "BuildingBlocks\EventBus\EventBus.Tests\EventBus.Tests.csproj", "{95D735BE-2899-4495-BE3F-2600E93B4E3C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.Tests", "BuildingBlocks\EventBus\EventBus.Tests\EventBus.Tests.csproj", "{95D735BE-2899-4495-BE3F-2600E93B4E3C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services.Common", "Services\Services.Common\Services.Common.csproj", "{CD430CE4-D5E0-4C96-84F5-AEC9162651B5}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services.Common", "Services\Services.Common\Services.Common.csproj", "{CD430CE4-D5E0-4C96-84F5-AEC9162651B5}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{42B85D0F-2ED6-4C00-91FA-103DACC3D5E2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{42B85D0F-2ED6-4C00-91FA-103DACC3D5E2}"
|
||||||
EndProject
|
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
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
|
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
|
||||||
@ -1532,6 +1536,54 @@ Global
|
|||||||
{CD430CE4-D5E0-4C96-84F5-AEC9162651B5}.Release|x64.Build.0 = Release|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{CD430CE4-D5E0-4C96-84F5-AEC9162651B5}.Release|x86.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -1590,6 +1642,8 @@ Global
|
|||||||
{95D735BE-2899-4495-BE3F-2600E93B4E3C} = {373D8AA1-36BE-49EC-89F0-6CB736666285}
|
{95D735BE-2899-4495-BE3F-2600E93B4E3C} = {373D8AA1-36BE-49EC-89F0-6CB736666285}
|
||||||
{CD430CE4-D5E0-4C96-84F5-AEC9162651B5} = {42B85D0F-2ED6-4C00-91FA-103DACC3D5E2}
|
{CD430CE4-D5E0-4C96-84F5-AEC9162651B5} = {42B85D0F-2ED6-4C00-91FA-103DACC3D5E2}
|
||||||
{42B85D0F-2ED6-4C00-91FA-103DACC3D5E2} = {91CF7717-08AB-4E65-B10E-0B426F01E2E8}
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9}
|
SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user