Rename some Zuul config keys
zuul.route -> zuul.routes zuul.mapping -> zuul.prefix
This commit is contained in:
@@ -44,7 +44,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
|
||||
@Override
|
||||
public void onApplicationEvent(EnvironmentChangeEvent event) {
|
||||
for (String key : event.getKeys()) {
|
||||
if (key.startsWith(properties.getMapping())) {
|
||||
if (key.startsWith("zuul.route")) {
|
||||
resetRoutes();
|
||||
return;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class RouteLocator implements ApplicationListener<EnvironmentChangeEvent>
|
||||
}
|
||||
|
||||
protected void addConfiguredRoutes(Map<String, String> routes) {
|
||||
Map<String, String> routeEntries = properties.getRoute();
|
||||
Map<String, String> routeEntries = properties.getRoutes();
|
||||
for (Map.Entry<String, String> entry : routeEntries.entrySet()) {
|
||||
String serviceId = entry.getKey();
|
||||
String route = entry.getValue() ;
|
||||
|
||||
@@ -58,8 +58,8 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping implements
|
||||
url = "/" + url;
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(properties.getMapping())) {
|
||||
url = properties.getMapping() + url;
|
||||
if (StringUtils.hasText(properties.getPrefix())) {
|
||||
url = properties.getPrefix() + url;
|
||||
if (!url.startsWith("/")) {
|
||||
url = "/" + url;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@Data
|
||||
@ConfigurationProperties("zuul")
|
||||
public class ZuulProperties {
|
||||
private String mapping = "";
|
||||
private boolean stripMapping = false;
|
||||
private Map<String,String> route = new HashMap<String, String>();
|
||||
private String prefix = "";
|
||||
private boolean stripPrefix = false;
|
||||
private Map<String,String> routes = new HashMap<String, String>();
|
||||
private boolean addProxyHeaders = true;
|
||||
private List<String> ignoredServices = Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ public class PreDecorationFilter extends ZuulFilter {
|
||||
|
||||
String requestURI = ctx.getRequest().getRequestURI();
|
||||
|
||||
String proxyMapping = properties.getMapping();
|
||||
String proxyMapping = properties.getPrefix();
|
||||
|
||||
final String uriPart;
|
||||
if (StringUtils.hasText(proxyMapping) && properties.isStripMapping()
|
||||
if (StringUtils.hasText(proxyMapping) && properties.isStripPrefix()
|
||||
&& requestURI.startsWith(proxyMapping)) {
|
||||
// TODO: better strategy?
|
||||
uriPart = requestURI.substring(proxyMapping.length());
|
||||
|
||||
@@ -41,7 +41,22 @@ public class RouteLocatorTests {
|
||||
public void testGetRoutes() {
|
||||
ZuulProperties properties = new ZuulProperties();
|
||||
RouteLocator routeLocator = new RouteLocator(this.discovery, properties);
|
||||
properties.getRoute().put(ASERVICE, "/"+ASERVICE + "/**");
|
||||
properties.getRoutes().put(ASERVICE, "/"+ASERVICE + "/**");
|
||||
|
||||
Map<String, String> routesMap = routeLocator.getRoutes();
|
||||
|
||||
assertNotNull("routesMap was null", routesMap);
|
||||
assertFalse("routesMap was empty", routesMap.isEmpty());
|
||||
assertMapping(routesMap, ASERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoutesWithMapping() {
|
||||
ZuulProperties properties = new ZuulProperties();
|
||||
RouteLocator routeLocator = new RouteLocator(this.discovery, properties);
|
||||
properties.getRoutes().put(ASERVICE, "/"+ASERVICE + "/**");
|
||||
// Prefix doesn't have any impact on the routes (it's used in the filter)
|
||||
properties.setPrefix("/foo");
|
||||
|
||||
Map<String, String> routesMap = routeLocator.getRoutes();
|
||||
|
||||
@@ -54,7 +69,7 @@ public class RouteLocatorTests {
|
||||
public void testGetPhysicalRoutes() {
|
||||
ZuulProperties properties = new ZuulProperties();
|
||||
RouteLocator routeLocator = new RouteLocator(this.discovery, properties);
|
||||
properties.getRoute().put("http://" + ASERVICE, "/"+ASERVICE + "/**");
|
||||
properties.getRoutes().put("http://" + ASERVICE, "/"+ASERVICE + "/**");
|
||||
|
||||
Map<String, String> routesMap = routeLocator.getRoutes();
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ endpoints:
|
||||
health:
|
||||
sensitive: false
|
||||
zuul:
|
||||
#mapping: /api
|
||||
#strip-mapping: true
|
||||
route:
|
||||
#prefix: /api
|
||||
#strip-prefix: true
|
||||
routes:
|
||||
testclient: /testing123/**
|
||||
http://localhost:8081: /stores/**
|
||||
|
||||
Reference in New Issue
Block a user