简体   繁体   English

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

[英]how to rename endpoints with express gateway?

i am trying to build an api that consists of different services and i want to everything to start with /api/ path. 我正在尝试构建一个由不同服务组成的api,我希望所有内容都以/ api /路径开头。 like the following below. 如下所示。

i want https://thirdparthy/comments to be routed as /api/comments on express gateway. 我希望将https:// thirdparthy / comments路由为Express网关上的/ api / comments。 what is the correct confirmation? 正确的确认是什么?

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

you can either use the rewrite policy to change the target url or simply configure the proxy policy accordingly: 您可以使用rewrite策略来更改目标url,也可以简单地相应地配置代理策略:

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

This should do the job. 这应该做的工作。

Cheers, 干杯,

V. V.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM