Skip to content

Instantly share code, notes, and snippets.

@fzankl
Last active September 14, 2021 17:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
YARP - Custom config provider with transformations
...
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