-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Can I use HttpContext to dynamically map to a remote API endpoint? #1510
Comments
I believe you can just use the MapPost method and then attach the AsBffApiEndpoint() to accomplish what you are looking for. app.MapPost("api/localpath", ctx => { ctx.RequestHeaders["XXX] == "1" ?
"https://new.domain.com/new-remote" :
"https://api.domain.com/default-remote"; })
.RequireAuthorization() // no anonymous access
.AsBffApiEndpoint(); // BFF pre/post processing |
@krispenner Did the above comment do the trick for you? |
Thank you @RolandGuijt, I didn’t realize I could do this. It would be helpful if you added overloads to your MapRemoteBffApiEndpoint that does this internally for us. Just to keep it simple and consistent. |
@RolandGuijt I am trying your suggestion but I can't find any Map() method that allows a simple string to be returned and it's not obvious to me what to do with the remote address selected based on the HttpContext. public static void MapRemoteEndpoints(this IEndpointRouteBuilder endpoints)
{
ArgCheck.NotNull(nameof(endpoints), endpoints);
var remoteEndpoints = endpoints.ServiceProvider.GetServices<RemoteApiEndpoint>();
foreach (var remoteEndpoint in remoteEndpoints)
{
var localPath = remoteEndpoint.LocalPath;
IEndpointConventionBuilder remoteEndpointBuilder;
if (remoteEndpoint.RemoteAddressSelector != null)
{
remoteEndpointBuilder = endpoints.Map(localPath, ctx =>
{
var remoteAddress = remoteEndpoint.RemoteAddressSelector(ctx); // Func<HttpContext, string>
return remoteAddress; // This does not work and it's not obvious what to do with this remote address string here.
}).AsBffApiEndpoint();
}
else
{
var remoteAddress = remoteEndpoint.RemoteAddress;
remoteEndpointBuilder = endpoints.MapRemoteBffApiEndpoint(localPath, remoteAddress);
}
// Configure BFF endpoint....
}
} |
The BFF has two configuration models for working with YARP:
We are not planning to add more features to the |
@krispenner Do you have additional questions around this issue or can we close it? |
Closing the issue for now but feel free to reopen if needed. |
Which version of Duende BFF are you using?
2.2.0
Which version of .NET are you using?
8.0
Describe the question
I'd like to use the HttpContext to dynamically decide the remote API endpoint to use at runtime.
Maybe this is exposed via some other means and you can point me there.
To Reproduce
The only thing I can seem to do is statically map the remote API endpoint.
Expected behavior
I'd like to dynamically chose the remote API endpoint based on the request.
The text was updated successfully, but these errors were encountered: