我遵循Express Gateway入门指南。
这是示例配置
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
host: localhost
paths: '/ip'
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
并且如果我运行npm start并浏览localhost:8080 / ip,则会看到响应。
但是如果我将localhost:8080 / ip导航到httpbin url时将其更改为“ localhost:3001”,则响应为“ Cannot GET ip /”。为什么???
在端口3001上,我有一个可以产生响应的工作服务
最后我找到了解决方案。在下面添加路径选项- action:
serviceEndpoint: {apiName}
ignorePath: false
prependPath: true
stripPath: true