Express 网关如何忽略路径但使用 url 的其余部分

Express gateway how to ignore path but use rest of the url

我的配置如下

apiEndpoints:
  api:
    host: '*'
    paths: '/ip'
  approval-engine:
    host: '*'
    paths: '/app/*'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
  approval-engine:
    url: 'http://localhost:8001/'

代理为

  - proxy:
      - action:
          serviceEndpoint: approval-engine
          ignorePath: false
          prependPath: false
          autoRewrite : true
          changeOrigin: true

当我向 http://localhost:8080/app/category 发出请求时,请求被路由到 localhost:8001/app/category

我的问题是我们能否将请求路由到 http://localhost:8001/category。我想忽略代理中的 paths:/app/ 部分。

为此,您需要使用 express-gateway rewrite plugin

您可以使用 eg CLI 安装插件。

eg plugin install express-gateway-plugin-rewrite

确保 rewrite 包含在网关配置的 policies 白名单中。

在处理请求的管道中,您可以像这样使用重写插件:

policies:
  - rewrite:
    - condition:
        name: regexpmatch
        match: ^/app/(.*)$
      action:
        rewrite: /

这应该在将请求路由到服务端点之前从路径中删除 /app