Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidfowl/aspireyarp
Yarp resource for Aspire.Hosting
https://github.com/davidfowl/aspireyarp
Last synced: about 2 months ago
JSON representation
Yarp resource for Aspire.Hosting
- Host: GitHub
- URL: https://github.com/davidfowl/aspireyarp
- Owner: davidfowl
- Created: 2024-01-27T05:59:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-17T22:32:09.000Z (8 months ago)
- Last Synced: 2024-10-15T05:28:05.138Z (2 months ago)
- Language: C#
- Homepage:
- Size: 14.6 KB
- Stars: 66
- Watchers: 6
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```C#
var builder = DistributedApplication.CreateBuilder(args);var app1 = builder.AddProject("app1");
var app2 = builder.AddProject("app2");
builder.AddYarp("ingress")
.WithEndpoint(hostPort: 8001, scheme: "http")
.Route("app1", path: "/app1", target: app1)
.Route("app2", path: "/app2", target: app2);builder.Build().Run();
```2. Configuration based routes
```C#
var builder = DistributedApplication.CreateBuilder(args);var app1 = builder.AddProject("app1");
var app2 = builder.AddProject("app2");
builder.AddYarp("ingress")
.WithEndpoint(hostPort: 8001, scheme: "http")
.WithReference(app1)
.WithReference(app2)
.LoadFromConfiguration("ReverseProxy");builder.Build().Run();
``````JSON
{
"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"
}
}
}
}
}
}
```