DuendeSoftware / Support

Support for Duende Software products
21 stars 0 forks source link

Remote API not getting called #827

Closed mrThirsty closed 1 year ago

mrThirsty commented 1 year ago

Which version of Duende BFF are you using? 2.1.1

Which version of .NET are you using? 7.0

Describe the bug

I have a hosted Blazor WASM application and a separate API. I have followed the steps to setup BFF in the Blazor app, and it authenticates and authorises the user fine in the application. I then followed the steps to Enable the proxy of the Remote API using the included Http forwarder, and the calls made by the Blazor App don't get routed to the remote API. For example:

remote API endpoint: https://localhost:7081/test

Blazor app makes a call to https://localhost:7202/api/test

All I get is the html of the blazor app index.html returned to me but I would expect it to end up hitting the remote API endpoint with the below config:

builder.Services.AddBff().AddRemoteApis(); ....

app.UseRouting();

app.UseAuthentication(); app.UseBff(); app.UseAuthorization();

app.MapBffManagementEndpoints();

app.MapRazorPages();

app.UseEndpoints(endpoints => { endpoints.MapRemoteBffApiEndpoint("/api/", "https://localhost:7081"); });

I have not enabled any Auth on the API right now as I want to get the proxy working first, but I can use postman to hit the remote endpoint and it is returning data. I am getting the same result if I replace the Http Forwarder with Yarp.

What am I missing that is causing the routing to not happen?

mrThirsty commented 1 year ago

I have managed to solve this issue. If someone runs into this, I had to switch to the YARP approach and then apply a Transform to the RouteConfig: "pathPattern": "{**catch-all}"

The proxy was trying to route https://localhost:7202/api/test to https://localhost:7081/api/test instead of https://localhost:7081/test.

The transform removes the "api" component of the path.