Skip to content
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

YARP service discovery broke for preview 5 & 6 ? #4137

Closed
swegele opened this issue May 9, 2024 · 5 comments
Closed

YARP service discovery broke for preview 5 & 6 ? #4137

swegele opened this issue May 9, 2024 · 5 comments
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@swegele
Copy link

swegele commented May 9, 2024

This was working at preview 4. Since 5 and 6 the wrong uri is returned. It returns the one for blazor website (itself) not the webapi.

This is from program.cs in the blazor web app (server side)

app.MapForwarder($"/{-mypathhere-}{{**catch-all}}", "https://mywebapi", transformBuilder =>
{                
    transformBuilder.AddRequestTransform(LocalAddRequestTransform);
}).RequireAuthorization();

program.cs from AppHost

var mywebapi = builder.AddProject<MyWebAPI>("mywebapi")
    ...

var websitemain = builder.AddProject<WebsiteMain>("websitemain")
    .WithReference(mywebapi);

The following are the actual URLs:
mywebapi = https://localhost:7182
websitemain = https://localhost:7237

When the YARP does it's thing, it sends the request to https://localhost:7237/api/projects...
That is wrong.
It should be (and was) https://localhost:7182/api/projects...

So to fix it for now I have to manually enter this and it works:

app.MapForwarder($"/{-mypathhere-}{{**catch-all}}", "https://localhost:7182", transformBuilder =>
{                
    transformBuilder.AddRequestTransform(LocalAddRequestTransform);
}).RequireAuthorization();

I didn't notice any new requirements to make service discovery work in the upgrade docs but maybe i missed something.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 9, 2024
@swegele swegele changed the title YARP service discovery broke for preview 5 & 6 YARP service discovery broke for preview 5 & 6 ? May 9, 2024
@DamianEdwards
Copy link
Member

@ReubenBond ?

@ReubenBond
Copy link
Member

I'm trying to spot the difference between this and what we have in our samples.

Do you have the call to builder.Services.AddHttpForwarderWithServiceDiscovery(); in your WebsiteMain project, @swegele?

@ReubenBond ReubenBond self-assigned this May 10, 2024
@swegele
Copy link
Author

swegele commented May 10, 2024

Yep program.cs of the blazor server web app...nestled in here between fluent and http...

builder.Services.AddFluentUIComponents();
builder.Services.AddHttpForwarderWithServiceDiscovery();
builder.Services.AddHttpContextAccessor();

I'm trying to spot the difference between this and what we have in our samples.

IKR - I've been scouring the lines too looking for something as I figured it had to be my fault...surely y'all would have seen such an obvious issue by now. The weird thing is that it actually does a replacement/lookup - it just gets the wrong one.

@swegele
Copy link
Author

swegele commented May 10, 2024

The only diff I see between eshop and mine is that I use the transformBuilder => action overload

Eshop

app.MapForwarder("/product-images/{id}", "http://catalog-api", "/api/v1/catalog/items/{id}/pic");

Mine

async ValueTask LocalAddRequestTransform(RequestTransformContext context)
{
    var accessToken = await context.HttpContext.GetTokenAsync("access_token");
    context.ProxyRequest.Headers.Authorization = new("Bearer", accessToken);
}


app.MapForwarder($"/api/projects/{{**catch-all}}", "https://mywebapi", transformBuilder =>
{                
    transformBuilder.AddRequestTransform(LocalAddRequestTransform);
}).RequireAuthorization();

That local function is for re-use because I currently have 4 different calls to MapForwarder

  • users api
  • projects api
  • organization api
  • signalr hub

@swegele
Copy link
Author

swegele commented May 18, 2024

This may or may not still be an issue, and if it is then others will find it and perhaps report it in a better way.

For now I simply changed to using the ToString() method of the URI used for my .AddHttpClient((...) methods.
Service discovery is working fine for those so why not just use that.

var myWebAPIBaseUri = new Uri("https://mywebapi");
and
myWebAPIBaseUri.ToString() in the .MapForwarder(...) methods.

@swegele swegele closed this as completed May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

3 participants