路由“0”需要指定主机或路径。将 Path 设置为 '/{**catchall}' 以匹配所有请求
Route '0' requires Hosts or Path specified. Set the Path to '/{**catchall}' to match all requests
我正在尝试在我的网关应用程序中使用 Yarp 来路由我的应用程序。但是,一旦启动,我就会收到“路由‘0’需要指定主机或路径。将路径设置为‘/{**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
知道我该如何解决这个问题吗?
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" } }
}
}
}
我正在尝试在我的网关应用程序中使用 Yarp 来路由我的应用程序。但是,一旦启动,我就会收到“路由‘0’需要指定主机或路径。将路径设置为‘/{**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
知道我该如何解决这个问题吗?
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" } }
}
}
}