Our team is migrating the API Gateway application from Netflix Zuul 1.x framework to Spring Cloud Gateway (SCG) 4.0 framework. There are more than 30 routes configured in the SCG application in the following format:
spring:
cloud:
gateway:
routes:
- id: SampleApiRoute
predicates:
- Path=/api/example/**
uri: https://samplehost.com:12345
- id: SampleRoute
predicates:
- Path=/example/**
uri: https://examplehost.com:56789
With above route configuration, SCG application redirects the incoming request, lets say /api/example/test, to downstream endpoint https://samplehost.com:12345/api/example/test, however the downstream server has exposed the endpoint at resource path as /test. Thus, SCG must redirect request to endpoint https://samplehost.com:12345/test instead.
Similarly, for incoming request (that matches second route), lets say /example/debug, SCG must redirect to endpoint https://examplehost.com:56789/debug.
Basically, SCG must be able to strip prefix predicate path from final downstream endpoint uri for redirection.
SCG framework provides StripPrefix Gateway filter to strip prefix from downstream endpoint, however it requires integer value as argument to decide how many path segment to strip.
Since, there are route configurations which have different number of path segments in predicate path attribute, like /api/example/** has 2 and /example/** has 1, so StripPrefix can not be applied as default filter for all configured routes.
https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway/gatewayfilter-factories/stripprefix-factory.html
This behavior is default behavior in Netflix Zuul framework.
Netflix Zuul framework provides stripPrefix attribute whose default value is true as follows:
zuul:
routes:
users:
path: /myusers/**
stripPrefix: true
https://cloud.spring.io/spring-cloud-static/Dalston.SR5/multi/multi__router_and_filter_zuul.html
Is there any similar settings or attributes provided by Spring Cloud Gateway framework as well that can be leveraged to strip prefix from all configured routes?