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) public static IServiceCollection AddReverseProxy(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy")) services.AddReverseProxy().LoadFromConfig(configuration.GetRequiredSection("ReverseProxy"));
.AddTransforms(builder =>
{
if (builder.Route?.Metadata?["prefix"] is string prefix)
{
builder.AddPathRemovePrefix($"/{prefix}");
}
});
return services; return services;
} }

View File

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