I am trying to use Yarp in my gateway app for routing my applications. However as soon as it's started, I get "Route '0' requires Hosts or Path specified. Set the Path to '/{**catchall}' to match all requests."
Here is my AppSettings file:
"ReverseProxy": {
"Routes": [
{
"SampleService": {
"ClusterId": "SampleService-cluster1",
"Match": {
"Host": "localhost",
"Path": "sample/{**catchall}"
}
},
"NotificationService": {
"ClusterId": "NotificationService-cluster",
"Match": {
"Host": "localhost",
"Path": "api/NotificationService/{**catchall}"
}
}
}
],
"Clusters": {
"SampleService-cluster1": {
"Destinations": { "SampleService-cluster1/destination1": { "Address": "http://127.0.0.1:6500" } }
},
"NotificationService-cluster": {
"Destinations": { "NotificationService-cluster/destination1": { "Address": "http://*:6020" } }
}
}
}
ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
services.AddCors(options =>
{
options.AddPolicy("any", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
services.AddControllers();
services.AddTelemetryConsumer<ForwarderTelemetry>();
services.AddReverseProxy()
.LoadFromConfig(Configuration.GetSection("ReverseProxy"));
}
And I get this: System.InvalidOperationException
So any idea how can I fix this?
CodePudding user response:
There was a breaking changes in v1.0.0-preview11 for the way Routes
are configured. You need to update your setting.
"ReverseProxy": {
"Routes": {
"SampleService": {
"ClusterId": "SampleService-cluster1",
"Match": {
"Host": "localhost",
"Path": "sample/{**catchall}"
}
},
"NotificationService": {
"ClusterId": "NotificationService-cluster",
"Match": {
"Host": "localhost",
"Path": "api/NotificationService/{**catchall}"
}
}
},
"Clusters": {
"SampleService-cluster1": {
"Destinations": { "SampleService-cluster1/destination1": { "Address": "http://127.0.0.1:6500" } }
},
"NotificationService-cluster": {
"Destinations": { "NotificationService-cluster/destination1": { "Address": "http://*:6020" } }
}
}
}