如何通过快速网关HTTPS提供管理API?

时间:2019-06-04 22:25:41

标签: express-gateway

我尝试设置我的快速网关,以便通过自己的HTTPS作为apiEndpoint / serviceEndpoint在快速网关上提供管理API。

下面是我的gateway-config.yml

我尽力遵守documentation中的说明。

https:
  port: 8443
  tls:
    'default':
      key: /usr/local/share/ca-certificates/ssl.key
      cert: /usr/local/share/ca-certificates/ssl.crt
admin:
  port: 8442
  host: localhost
serviceEndpoints:
  someExampleBackend:
    url: https://some.example.com
  adminBackend:
    url: http://localhost:8442
policies:
  - proxy
pipelines:
  adminAPI:
    apiEndpoints:
      - admin
    policies:
      - proxy:
          - action:
              serviceEndpoint: adminBackend
  domeExampleAPI:
    apiEndpoints:
      - general
      - proxy:
          - action:
              serviceEndpoint: someExampleBackend
apiEndpoints:
  admin:
    host: localhost
  general:
    host: localhost
    methods:
      - GET
      - POST
      - PUT
      - DELETE
      - OPTIONS
    paths:
      - "/echo"

我希望能够使用这样的管理API:

https://localhost:8443/api-endpoints

同时示例通用端点如下:

https://localhost:8443/echo

这样做时,只有admin API可以正常工作。所有其他apiEndpoints返回404“ Cannot GET / echo”。 当我用admin删除所有内容或仅更改主机时,其他apiEndpoints才能正常工作。

我该如何解决该任务?

1 个答案:

答案 0 :(得分:0)

经过更多尝试和错误后解决。

对于所有其他为此苦苦挣扎的人:您可以使用重写策略。

https:
  port: 8443
  tls:
    'default':
      key: /usr/local/share/ca-certificates/ssl.key
      cert: /usr/local/share/ca-certificates/ssl.crt
admin:
  port: 8442
  host: localhost
serviceEndpoints:
  someExampleBackend:
    url: https://some.example.com
  adminBackend:
    url: http://localhost:8442
policies:
  - proxy
pipelines:
  adminAPI:
    apiEndpoints:
      - admin
    policies:
      - rewrite:
          - condition:
              name: pathmatch
              match: /adminapi/:route*
            action:
              rewrite: /:route
      - proxy:
          - action:
              serviceEndpoint: adminBackend
  domeExampleAPI:
    apiEndpoints:
      - general
      - proxy:
          - action:
              serviceEndpoint: someExampleBackend
apiEndpoints:
  admin:
    host: localhost
    paths: "/adminapi/*"
  general:
    host: localhost
    methods:
      - GET
      - POST
      - PUT
      - DELETE
      - OPTIONS
    paths:
      - "/echo"