首页 > 解决方案 > 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

标签: node.jsexpressapi-gateway

解决方案


这是预期的,因为 apiEndpoints 配置部分使用相同的主机和路径来构建路由

apiEndpoints:
  config:
    host: localhost
  actions:
    host: localhost

你可以做的是通过路径以某种方式将它分开

apiEndpoints:
  config:
    path: /configs
  actions:
    path: /actions

这样localhost/configs/db将转到配置服务..:3002/configs/dblocalhost/actions/magic执行操作..:3006/actions/magic

您可能还想安装 Rewrite 插件 https://www.express-gateway.io/docs/policies/rewrite/

如果目标服务具有不同的 URL 模式


推荐阅读