Last active
September 14, 2021 17:04
-
-
Save fzankl/2983bb6e34e32076be1caa6014169075 to your computer and use it in GitHub Desktop.
YARP - Custom config provider with transformations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public CustomProxyConfigProvider() | |
{ | |
// Load a basic configuration | |
// Should be based on your application needs. | |
var routeConfig = new RouteConfig | |
{ | |
RouteId = "route1", | |
ClusterId = "cluster1", | |
Match = new RouteMatch | |
{ | |
Path = "/api/service1/{**catch-all}" | |
} | |
}; | |
routeConfig = routeConfig | |
.WithTransformPathRemovePrefix(prefix: "/api/service1/") | |
.WithTransformResponseHeader(headerName: "Source", value: "YARP", append: true, always: false); | |
var routeConfigs = new[] { routeConfig }; | |
var clusterConfigs = new[] | |
{ | |
new ClusterConfig | |
{ | |
ClusterId = "cluster1", | |
LoadBalancingPolicy = LoadBalancingPolicies.RoundRobin, | |
Destinations = new Dictionary<string, DestinationConfig> | |
{ | |
{ "destination1", new DestinationConfig { Address = "https://localhost:5001/" } }, | |
{ "destination2", new DestinationConfig { Address = "https://localhost:5002/" } } | |
} | |
} | |
}; | |
_config = new CustomMemoryConfig(routeConfigs, clusterConfigs); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment