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 proxy not forwarding to origins #2

Open
Kralizek opened this issue Apr 22, 2024 · 4 comments
Open

YARP proxy not forwarding to origins #2

Kralizek opened this issue Apr 22, 2024 · 4 comments

Comments

@Kralizek
Copy link

Hi,

The YARP proxy is not forwarding the call to the origins.

I created a repro of the issue here: https://github.com/Kralizek/AspireYarpIssueRepro

The project includes:

  • A webapi project called API
  • A second webapi project called LegacyAPI
  • The ServiceDefaults project
  • A AppHost project that includes the YarpResource from this repro.

The AppHost program file looks like this:

using AppHost.Extensions;

var builder = DistributedApplication.CreateBuilder(args);

var api = builder.AddProject<Projects.API>("api");

var legacy = builder.AddProject<Projects.LegacyAPI>("legacy");

builder.AddYarp("test")
    .Route("legacy", legacy, path: "/legacy", preservePath: false)
    .Route("api", api, path: YarpResource.CatchAll);

builder.Build().Run();

When I run the solution

$ dotnet run --project .\tools\AppHost\

Building...
info: Aspire.Hosting.DistributedApplication[0]
      Aspire version: 8.0.0-preview.5.24201.12+1b627b7d5d399d4f9118366e7611e11e56de4554
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
      Application host directory is: C:\Users\RenatoGolia\Development\GitHub\AspireYarpIssueRepro\tools\AppHost
info: Aspire.Hosting.DistributedApplication[0]
      Now listening on: https://localhost:17284
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application started. Press Ctrl+C to shut down.

I get the following on the dashboard

image

Unfortunately, when I navigate to http://127.0.0.1:63438/weatherforecast (that should be forwarded to https://localhost:7270/weatherforecast) I get redirected to https://api:7270/weatherforecast.

Similarly, when I navigate to http://127.0.0.1:63438/legacy/weatherforecast (that should be forwarded to https://localhost:7018/weatherforecast), I get redirected to https://api:7270/legacy/weatherforecast.

I wasn't able to reproduce the issue with the transformation as explained here. I'll keep investigating on why it doesn't work on my main project.

Thanks for your help!

@JohnGalt1717
Copy link

I'm getting similar with P6 and configuration file based setup. I get a 502 error and there's also an SSL Certificate error in the logs.

@Kralizek
Copy link
Author

@davidfowl were you able to reproduce the problem detailed in the issue?

@JohnGalt1717
Copy link

@Kralizek I was able to fix this by adding :

"Host": "localhost",

To all of my clusters. It then started working again.

@Kralizek
Copy link
Author

Kralizek commented Apr 29, 2024

@Kralizek I was able to fix this by adding :

"Host": "localhost",

To all of my clusters. It then started working again.

Adding this solved the issue with the hostname in the link, but I still get a redirect...

builder.Resource.ClusterConfigs[target.Resource.Name] = new()
{
    ClusterId = target.Resource.Name,
    Destinations = new Dictionary<string, DestinationConfig>
    {
        [target.Resource.Name] = new() { 
            Address = $"http://{target.Resource.Name}",
            Host = builder.ApplicationBuilder.ExecutionContext.IsRunMode ? "localhost" : default
        }
    }
};

image

EDIT: adding the following solved the redirect issue.

var proxyBuilder = builder.Services
    .AddReverseProxy()
    .ConfigureHttpClient((context, handler) => handler.AllowAutoRedirect = true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants