简体   繁体   中英

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. like the following below.

i want https://thirdparthy/comments to be routed as /api/comments on express gateway. 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:

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

This should do the job.

Cheers,

V.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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