我正在嘗試在我的網關應用程式中使用 Yarp 來路由我的應用程式。但是,一旦啟動,我就會收到“Route '0' requires Hosts or Path specified。將 Path 設定為 '/{**catchall}' 以匹配所有請求。”
這是我的 AppSettings 檔案:
"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" } }
}
}
}
配置服務:
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"));
}
我得到這個: System.InvalidOperationException
那么知道如何解決這個問題嗎?
uj5u.com熱心網友回復:
v1.0.0-preview11中的Routes配置方式發生了重大變化。您需要更新您的設定。
"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" } }
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/393732.html
