node.js - Express 网关无法 GET
问题描述
我正在尝试在快速网关中设置多个(nodejs)服务,但是由于某种原因,第二个服务没有被拾取。请在下面找到我的 gateway.config.yml
http:
port: 8080
admin:
port: 9876
hostname: localhost
apiEndpoints:
config:
host: localhost
actions:
host: localhost
serviceEndpoints:
configService:
url: "http://localhost:3002"
actionService:
url: "http://localhost:3006"
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
- name: basic
apiEndpoints:
- config
policies:
- proxy:
- action:
serviceEndpoint: configService
changeOrigin: true
- name: basic2
apiEndpoints:
- actions
policies:
- proxy:
- action:
serviceEndpoint: actionService
changeOrigin: true
解决方案
这是预期的,因为 apiEndpoints 配置部分使用相同的主机和路径来构建路由
apiEndpoints:
config:
host: localhost
actions:
host: localhost
你可以做的是通过路径以某种方式将它分开
apiEndpoints:
config:
path: /configs
actions:
path: /actions
这样localhost/configs/db
将转到配置服务..:3002/configs/db
并localhost/actions/magic
执行操作..:3006/actions/magic
您可能还想安装 Rewrite 插件 https://www.express-gateway.io/docs/policies/rewrite/
如果目标服务具有不同的 URL 模式
推荐阅读
- java - 将捕获图像数据插入片段中的 ImageView 时出错
- reactjs - 将数字传递给反应js中的函数
- python - 我收到此错误---> TypeError: integer argument expected, got float
- sendgrid - Sendgrid 的链接产生无法建立安全连接
- windows - 在 ubuntu 上解压后文件名错误
- node.js - 如何在 Nestjs 中将 axios 内容从“text/html”更改为 application/json 类型
- java - Recyclerview 和 OkHttp 请求同步
- python-3.x - 为什么这个除法的结果是“inf”?
- docker - ARG 值是否传递给使用 RUN 执行的脚本
- jenkins - 从 jenkins 扩展选择参数中获取源值