-
I would like to define a route as Note any valid "clusterName" here would only have a single destination. I think there's a few ways to do this: custom transform and setting Which one is the preferred way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'd say the preferred approach depends on how many such clusters you have / whether they're dynamic (you add/remove them while the proxy is running). If you only have a handful of static ones, you could simply define them all in the configuration file. If there are a lot of different ones / they're updated often, it may be easiest to switch to a code-based approach. Since you mentioned only having one destination per cluster, you're unlikely to benefit from features such as session affinity, load balancing, or health checks, so you could look at using direct forwarding. var destinations = new Dictionary<string, string>
{
{ "foo", "https://foo.com" }
};
app.Map("/p/{clusterName}/{**remainder}", async (HttpContext context, IHttpForwarder forwarder,
[FromRoute] string clusterName,
[FromRoute] string remainder) =>
{
if (destinations.TryGetValue(clusterName, out var destination))
{
context.Request.Path = $"/{remainder}";
await forwarder.SendAsync(context, destination, client);
}
}); |
Beta Was this translation helpful? Give feedback.
I'd say the preferred approach depends on how many such clusters you have / whether they're dynamic (you add/remove them while the proxy is running).
If you only have a handful of static ones, you could simply define them all in the configuration file.
If there are a lot of different ones / they're updated often, it may be easiest to switch to a code-based approach. Since you mentioned only having one destination per cluster, you're unlikely to benefit from features such as session affinity, load balancing, or health checks, so you could look at using direct forwarding.
E.g. something along the lines of