Use YARP native config

This commit is contained in:
David Fowler 2023-05-07 18:18:22 -07:00 committed by Reuben Bond
parent 69476a3175
commit 64a2d69e92
2 changed files with 19 additions and 26 deletions

View File

@ -4,14 +4,7 @@ internal static class Extensions
{
public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration)
{
services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy"))
.AddTransforms(builder =>
{
if (builder.Route?.Metadata?["prefix"] is string prefix)
{
builder.AddPathRemovePrefix($"/{prefix}");
}
});
services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy"));
return services;
}

View File

@ -35,54 +35,54 @@
"Match": {
"Path": "c/{**catch-all}"
},
"Metadata": {
"prefix": "c"
}
"Transforms": [
{ "PathRemovePrefix": "/c" }
]
},
"c-long": {
"ClusterId": "catalog",
"Match": {
"Path": "catalog-api/{**catch-all}"
},
"Metadata": {
"prefix": "catalog-api"
}
"Transforms": [
{ "PathRemovePrefix": "/catalog-api" }
]
},
"b-short": {
"ClusterId": "basket",
"Match": {
"Path": "b/{**catch-all}"
},
"Metadata": {
"prefix": "b"
}
"Transforms": [
{ "PathRemovePrefix": "/b" }
]
},
"b-long": {
"ClusterId": "basket",
"Match": {
"Path": "basket-api/{**catch-all}"
},
"Metadata": {
"prefix": "basket-api"
}
"Transforms": [
{ "PathRemovePrefix": "/basket-api" }
]
},
"o-short": {
"ClusterId": "orders",
"Match": {
"Path": "o/{**catch-all}"
},
"Metadata": {
"prefix": "o"
}
"Transforms": [
{ "PathRemovePrefix": "/o" }
]
},
"o-long": {
"ClusterId": "orders",
"Match": {
"Path": "ordering-api/{**catch-all}"
},
"Metadata": {
"prefix": "ordering-api"
}
"Transforms": [
{ "PathRemovePrefix": "/ordering-api" }
]
},
"h-long": {
"ClusterId": "signalr",