如何使用Express Gateway重命名端点?

时间:2018-07-30 14:11:07

标签: express-gateway

我正在尝试构建一个包含不同服务的api,并且我希望所有内容都以/ api /路径开头。如下所示。

我希望https://thirdparthy/comments在Express网关上作为/ api / comments路由。正确的确认是什么?

http:
  port: 4000
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  users:
    host: localhost
    paths: '/api/users'
  comments:
    host: localhost
    paths: '/api/comments'
serviceEndpoints:
  users:
    url: 'https://jsonplaceholder.typicode.com/users'
  comments:
    url: 'https://jsonplaceholder.typicode.com/comments'
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  users:
    apiEndpoints:
      - users
    policies:
      - proxy:
          - action:
              serviceEndpoint: users 
              prependPath: false
              ignorePath: false
  comments:
    apiEndpoints:
      - comments
    policies:
      - proxy:
          - action:
              serviceEndpoint: comments 
              prependPath: false
              ignorePath: false

1 个答案:

答案 0 :(得分:1)

您可以使用rewrite策略来更改目标网址,也可以相应地简单地配置代理策略:

- proxy: - action: serviceEndpoint: comments prependPath: true ignorePath: false

这应该可以完成工作。

干杯

V。