From 383a204bcfc58478b770af4f9337e95f85ff6271 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 19 Dec 2018 19:59:51 -0500 Subject: [PATCH] Adding documentation on customizing DiscoveryClient predicates and filters. Fixes #637 --- .../main/asciidoc/spring-cloud-gateway.adoc | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-gateway.adoc b/docs/src/main/asciidoc/spring-cloud-gateway.adoc index 5897035c..677f6b87 100644 --- a/docs/src/main/asciidoc/spring-cloud-gateway.adoc +++ b/docs/src/main/asciidoc/spring-cloud-gateway.adoc @@ -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/(?.*)` 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 + '/(?.*)'" +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`].