Adding documentation on customizing DiscoveryClient predicates and filters. Fixes #637
This commit is contained in:
@@ -1079,6 +1079,38 @@ The Gateway can be configured to create routes based on services registered with
|
||||
|
||||
To enable this, set `spring.cloud.gateway.discovery.locator.enabled=true` and make sure a `DiscoveryClient` implementation is on the classpath and enabled (such as Netflix Eureka, Consul or Zookeeper).
|
||||
|
||||
|
||||
==== Configuring Predicates and Filters For DiscoveryClient Routes
|
||||
|
||||
By default the Gateway defines a single predicate and filter for routes created via a `DiscoveryClient`.
|
||||
|
||||
The default predicate is a path predicate defined with the pattern `/serviceId/**`, where `serviceId` is
|
||||
the id of the service from the `DiscoveryClient`.
|
||||
|
||||
The default filter is rewrite path filter with the regex `/serviceId/(?<remaining>.*)` and the replacement
|
||||
`/${remaining}`. This just strips the service id from the path before the request is sent
|
||||
downstream.
|
||||
|
||||
If you would like to customize the predicates and/or filters used by the `DiscoveryClient` routes you can do so
|
||||
by setting `spring.cloud.gateway.discovery.locator.predicates[x]` and `spring.cloud.gateway.discovery.locator.filters[y]`.
|
||||
When doing so you need to make sure to include the default predicate and filter above, if you want to retain
|
||||
that functionality. Below is an example of what this looks like.
|
||||
|
||||
.application.properties
|
||||
[soure,properties]
|
||||
----
|
||||
spring.cloud.gateway.discovery.locator.predicates[0].name: Path
|
||||
spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]: "'/'+serviceId+'/**'"
|
||||
spring.cloud.gateway.discovery.locator.predicates[1].name: Host
|
||||
spring.cloud.gateway.discovery.locator.predicates[1].args[pattern]: "'**.foo.com'"
|
||||
spring.cloud.gateway.discovery.locator.filters[0].name: Hystrix
|
||||
spring.cloud.gateway.discovery.locator.filters[0].args[name]: serviceId
|
||||
spring.cloud.gateway.discovery.locator.filters[1].name: RewritePath
|
||||
spring.cloud.gateway.discovery.locator.filters[1].args[regexp]: "'/' + serviceId + '/(?<remaining>.*)'"
|
||||
spring.cloud.gateway.discovery.locator.filters[1].args[replacement]: "'/${remaining}'"
|
||||
----
|
||||
|
||||
|
||||
== CORS Configuration
|
||||
|
||||
The gateway can be configured to control CORS behavior. The "global" CORS configuration is a map of URL patterns to https://docs.spring.io/spring/docs/5.0.x/javadoc-api/org/springframework/web/cors/CorsConfiguration.html[Spring Framework `CorsConfiguration`].
|
||||
|
||||
Reference in New Issue
Block a user