-
If I'm using a Hosts filter on a route like
does yarp use the incoming port of 5000 on the destination selected in the cluster? Or does it have to be explicitly mapped for every single port, where each port is a separate application? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
No, YARP will use the address prefix as-is, the port is not copied over. You can either specify the exact ports you want to use on the backend, or you can use a transform to modify requests, e.g. builder.Services.AddReverseProxy()
.LoadFromMemory(GetRoutes(), GetClusters())
.AddTransforms(transforms =>
{
transforms.AddRequestTransform(context =>
{
var uri = RequestUtilities.MakeDestinationAddress(context.DestinationPrefix, context.Path, context.Query.QueryString);
uri = new UriBuilder(uri) { Port = context.HttpContext.Connection.LocalPort }.Uri;
context.ProxyRequest.RequestUri = uri;
return default;
});
}); will set the destination port to the connection's local port. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I didn't want to have to define a separate cluster for every single app, since they're all the same servers, but it looks like I need to define the destinations with the port for each one then. I wasn't doing it in code because I may be adding things that don't follow the same pattern. |
Beta Was this translation helpful? Give feedback.
No, YARP will use the address prefix as-is, the port is not copied over.
You can either specify the exact ports you want to use on the backend, or you can use a transform to modify requests, e.g.