0

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:

  • I have a controller in every app that has '/' as an entry point (home page)
  • I can use java configuration instead if necessary

Any advice will be appreciated! Cheers!

1 Answer 1

1

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}

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! works like a charm! I ended with the following - RewritePath=/bar(?<segment>.*), /bar/$\{segment}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.