Numan Medina
Numan Medina

Reputation: 27

Spring Cloud Gateway Route URL pattern configuration

I'm have implemented Spring Cloud Gateway with Eureka discovery service, everything works fine but I have seen something that I don't know how to deal with when I write the URL and if I don't put a / at the end of the URL the gateway redirects to the app directly using its actual URL (registered in Eureka).

For example:

Is there a configuration to avoid the first situation?

My configuration is the following:

spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      routes:
        - id: bar-service
          uri: lb://BAR-SERVICE/
          predicates:
            - Path=/bar/**
        - id: other-service
          uri: lb://OTHER-SERVICE/
          predicates:
            - Path=/OTHER/**

Additional information:

Any advice will be appreciated! Cheers!

Upvotes: 0

Views: 1389

Answers (1)

jacky-neo
jacky-neo

Reputation: 853

You should use RewritePath in gateway configuration. The below is sample and hope it helpful to you.

spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      routes:
        - id: bar-service
          uri: lb://BAR-SERVICE/
          predicates:
            - Path=/bar/**
          filters:
            - RewritePath=/bar(?<segment>.*), /$\{segment}

Upvotes: 1

Related Questions