ocelot可以用于组合有角度的应用程序和api,还是仅适用于路由api?

问题描述 投票:0回答:1

我正在将Ocelot-API网关用于.NET Corehttps://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应用,其优缺点是什么]

asp.net-core reverse-proxy api-gateway ocelot
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"
    }
}

Ref:

  • Ocelot入门

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

  • 豹猫路线

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

© www.soinside.com 2019 - 2024. All rights reserved.