Skip to content

Instantly share code, notes, and snippets.

@fzankl
Last active September 14, 2021 17:04
Show Gist options
  • Save fzankl/2983bb6e34e32076be1caa6014169075 to your computer and use it in GitHub Desktop.
Save fzankl/2983bb6e34e32076be1caa6014169075 to your computer and use it in GitHub Desktop.
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