0

我想在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 Gateway,并且我想重定向到服务 1

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

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

服务 2 也一样。

我为 spring 云网关使用 yml 配置。

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

提前致谢。

4

1 回答 1

2
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 云网关参考将为您提供更多详细信息。

于 2019-10-29T06:50:56.537 回答