0

我正在使用 Ocelot - .NET Core 的 API 网关 https://github.com/ThreeMammals/Ocelot

设想:

我有以下网站

  • Ocelot API 网关 .NET Core
  • 站点 A - Angular 应用程序
  • 站点 B - .net 核心 API
  • 站点 C - .net 核心 API

现在我想要的是所有请求都应该首先从那里到达 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 应用程序,它的优缺点是什么

4

1 回答 1

0

我做了类似的事情,按照你的例子,应该是这样的:

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"
    }
}

参考:

  • 豹猫入门

https://ocelot.readthedocs.io/en/latest/introduction/gettingstarted.html

  • 豹猫路由

https://ocelot.readthedocs.io/en/latest/features/routing.html

于 2020-01-22T11:50:51.770 回答