我正在将Ocelot-API网关用于.NET Corehttps://github.com/ThreeMammals/Ocelot
场景:
我有以下站点
现在我想要的是所有请求都应首先从那里到达ocelot,它将重定向到相应的应用程序和API
请求首先从那里转到Ocelot,路由应该如下所述进行
/ - route to the angular app (Site A )
/b - route to API (Site B)
/c - route to API (Site C)
我能够将/ b和/ c路由到相应的API和应用。仅仅需要知道ocelot是否适合路由到App,就像我在这里使用Angular一样,或者它是为路由微服务中的api而设计的。如果使用angular应用,其优缺点是什么]
我做了类似的事情,按照您的示例,应该是这样的:
ocelot项目中的配置:
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/b/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5002
}
],
"UpstreamPathTemplate": "/b/{everything}",
"UpstreamHttpMethod": [ "Get","Post" ]
},
{
"DownstreamPathTemplate": "/c/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5003
}
],
"UpstreamPathTemplate": "/c/{everything}",
"UpstreamHttpMethod": [ "Get","Post" ]
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamPathTemplate": "/{everything}",
"UpstreamHttpMethod": [ "Get","Post" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://entrypointurl.com"
}
}
Ref:
https://ocelot.readthedocs.io/en/latest/introduction/gettingstarted.html
https://ocelot.readthedocs.io/en/latest/features/routing.html