如何使用快速网关重命名端点?
how to rename endpoints with 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
您可以使用 rewrite
策略来更改目标 url 或者简单地相应地配置代理策略:
- proxy:
- action:
serviceEndpoint: comments
prependPath: true
ignorePath: false
这应该可以完成工作。
干杯,
V.
我正在尝试构建一个包含不同服务的 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
您可以使用 rewrite
策略来更改目标 url 或者简单地相应地配置代理策略:
- proxy:
- action:
serviceEndpoint: comments
prependPath: true
ignorePath: false
这应该可以完成工作。
干杯,
V.