为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Spring Cloud Gateway中添加额外的路径到uri

如何在Spring Cloud Gateway中添加额外的路径到uri

Smart猫小萌 2024-01-05 10:21:56
我想在 Spring Cloud Gateway 中为不同的 api 添加自定义路径。我有两个API:服务1:http://localhost:2121服务 1 的端点如下:http://localhost:2121/abc服务2:http://localhost:3434服务 2 的端点如下http://localhost:3434/abcAPI网关:http://localhost:8090问题:我想将 service1 路径添加到 API Gateway,并且我想重定向到服务 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提前致谢。
查看完整描述

1 回答

?
繁星淼淼

TA贡献1775条经验 获得超11个赞

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'。

查看完整回答
反对 回复 2024-01-05
  • 1 回答
  • 0 关注
  • 54 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信