Route a request to CDN backend #2342
-
After reading the docs i think maybe this is the correct approach: app.MapReverseProxy(proxyPipeline =>
{
proxyPipeline.Use((context, next) =>
{
var proxyFeature = context.GetReverseProxyFeature();
var destinations = proxyFeature.AvailableDestinations;
var destinationState = new DestinationState("cdnDefault", new DestinationModel(new DestinationConfig()
{
Address = "https://cdn.mydomain.net/some-location"
}));
proxyFeature.Route.Config.WithTransform(x => x.Add("PathSet", "/some-id"));
proxyFeature.AvailableDestinations = new List<DestinationState>() { destinationState }.AsReadOnly();
return next();
});
proxyPipeline.UseSessionAffinity();
proxyPipeline.UseLoadBalancing();
proxyPipeline.UsePassiveHealthChecks();
}); but after checking the logs instead of routing to https://cdn.mydomain.net/some-location/some-id it routes to https://cdn.mydomain.net/some-location + PathString . I tried also |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
The route transforms can't be modified in middleware per request. Add that destination and transform in config when defining your route. https://microsoft.github.io/reverse-proxy/articles/config-files.html
If you need more flexibility then try https://microsoft.github.io/reverse-proxy/articles/direct-forwarding.html |
Beta Was this translation helpful? Give feedback.
Using direct forwarding that Chris mentioned is likely the easiest option to achieve what you're trying to do: https://microsoft.github.io/reverse-proxy/articles/direct-forwarding.html
For example, you can have a middleware before YARP that looks something like this (untested):