Skip to content

davidfowl/AspireYarp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aspire.Hosting.Yarp

This is a sample project that shows how use YARP in development to route between multiple services.

Getting Started

There are 2 ways to use the YARP resource:

  1. Code based routes
var builder = DistributedApplication.CreateBuilder(args);

var app1 = builder.AddProject<Projects.WebApplication1>("app1");

var app2 = builder.AddProject<Projects.WebApplication2>("app2");

builder.AddYarp("ingress")
       .WithEndpoint(hostPort: 8001, scheme: "http")
       .Route("app1", path: "/app1", target: app1)
       .Route("app2", path: "/app2", target: app2);

builder.Build().Run();
  1. Configuration based routes
var builder = DistributedApplication.CreateBuilder(args);

var app1 = builder.AddProject<Projects.WebApplication1>("app1");

var app2 = builder.AddProject<Projects.WebApplication2>("app2");

builder.AddYarp("ingress")
    .WithEndpoint(hostPort: 8001, scheme: "http")
    .WithReference(app1)
    .WithReference(app2)
    .LoadFromConfiguration("ReverseProxy");

builder.Build().Run();
{
  "ReverseProxy": {
    "Routes": {
      "app1": {
        "ClusterId": "app1",
        "Match": {
          "Path": "/app1"
        },
        "Transforms": [
          { "PathRemovePrefix": "/app1" }
        ]
      },
      "app2": {
        "ClusterId": "app2",
        "Match": {
          "Path": "/app2"
        },
        "Transforms": [
          { "PathRemovePrefix": "/app2" }
        ]
      }
    },
    "Clusters": {
      "app1": {
        "Destinations": {
          "app1": {
            "Address": "http://app1"
          }
        }
      },
      "app2": {
        "Destinations": {
          "app2": {
            "Address": "http://app2"
          }
        }
      }
    }
  }
}

About

Yarp resource for Aspire.Hosting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages