【发布时间】:2020-02-11 14:10:13
【问题描述】:
您将如何根据两组相似的路由设置重新路由到不同的机器。请指教。
问题/问题:冲突的情况是在/customers/1 和/customers/1/products 之间,每个人都去不同的机器。
- 机器名称:customer
GET /customers
GET /customers/1
POST /customers
PUT /customers1
DELETE /customers/1
- 机器名称:customerproduct
GET /customers/1/products
PUT /customers/1/products
ocelot.json
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/customers/{id}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "customer",
"Port": 80
}
],
"UpstreamPathTemplate": "/customers/{id}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
},
{
"DownstreamPathTemplate": "/customers/{id}/products",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "customerproduct",
"Port": 80
}
],
"UpstreamPathTemplate": "/customers/{id}/products",
"UpstreamHttpMethod": [ "Get", "Put" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:80"
}
}
【问题讨论】:
-
为什么这不起作用?你得到什么错误?
-
问题是
/customers/{id}被/customers/1和/customers/1/product1拦截 -
通过更改顺序解决,将最具体的路线上移到通用路线。
-
你想添加这个作为答案还是我应该这样做:)
-
我已经做到了。希望没关系
标签: .net-core microservices url-routing service-discovery ocelot