【问题标题】:How to add extra path to uri in spring cloud gatway如何在 Spring Cloud Gateway 中为 uri 添加额外路径
【发布时间】:2020-02-24 09:35:33
【问题描述】:

我想在spring cloud gateway中为不同的api添加自定义路径。

我有两个 api:

  1. 服务1:http://localhost:2121

服务 1 的端点类似于:http://localhost:2121/abc

  1. 服务2:http://localhost:3434

服务 2 的端点类似于 http://localhost:3434/abc

api网关:http://localhost:8090

问题:

我想将 service1 路径添加到 API 网关,并且我想重定向到服务 1

示例 1:http://localhost:8090/service1/abc 应重定向到 http://localhost:2121/abc

示例 2:http://localhost:8090/service1/anything 应重定向到 http://localhost:2121/anything

服务 2 也一样。

spring cloud gateway我使用yml配置。

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        - id: service1
          uri: http://localhost:2121
        - id: service2
          uri: http://localhost:3434

提前致谢。

【问题讨论】:

    标签: java spring cloud gateway


    【解决方案1】:
    spring:
        cloud:
            gateway:
                routes:
                -  id: service1
                   uri: http://localhost:2121
                   predicates:
                   -   Path=/service1/**
                   filters:
                   -   StripPrefix=1
                -  id: service2
                   uri: http://localhost:3434
                   predicates:
                   -   Path=/service2/**
                   filters:
                   -   StripPrefix=1
    

    那么所有映射“/service1/xxxx”的请求都会代理到service_1“/xxxx”。

    spring cloud gateway reference 将为您提供更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 2019-09-16
      • 2023-01-21
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 2018-07-15
      相关资源
      最近更新 更多