Fixes css and js for eureka dashboard
This commit is contained in:
@@ -180,15 +180,9 @@
|
||||
<dependencies>
|
||||
<!-- https://github.com/wro4j/wro4j/issues/1129 -->
|
||||
<dependency>
|
||||
<groupId>ro.isdc.wro4j</groupId>
|
||||
<artifactId>wro4j-extensions</artifactId>
|
||||
<version>1.10.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
<artifactId>minimatch</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
<artifactId>glob</artifactId>
|
||||
<version>7.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.netflix.appinfo.ApplicationInfoManager;
|
||||
import com.netflix.discovery.EurekaClient;
|
||||
@@ -64,6 +65,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.cloud.client.actuator.HasFeatures;
|
||||
@@ -81,6 +83,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@@ -103,6 +106,11 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
*/
|
||||
private static final String[] EUREKA_PACKAGES = new String[] { "com.netflix.discovery", "com.netflix.eureka" };
|
||||
|
||||
/**
|
||||
* Static content pattern for dashboard elements (images, css, etc...).
|
||||
*/
|
||||
private static final String STATIC_CONTENT_PATTERN = "/(fonts|images|css|js)/.*";
|
||||
|
||||
@Autowired
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
|
||||
@@ -223,19 +231,23 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<?> eurekaVersionFilterRegistration() {
|
||||
public FilterRegistrationBean<?> eurekaVersionFilterRegistration(ServerProperties serverProperties) {
|
||||
String contextPath = serverProperties.getServlet().getContextPath();
|
||||
String regex = EurekaConstants.DEFAULT_PREFIX + STATIC_CONTENT_PATTERN;
|
||||
if (StringUtils.hasText(contextPath)) {
|
||||
regex = contextPath + regex;
|
||||
}
|
||||
Pattern staticPattern = Pattern.compile(regex);
|
||||
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
|
||||
bean.setFilter(new OncePerRequestFilter() {
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
HttpServletRequest req = request;
|
||||
String contextPath = request.getContextPath();
|
||||
String pathInfo = request.getPathInfo();
|
||||
String requestURI = request.getRequestURI();
|
||||
String servletPath = request.getServletPath();
|
||||
String requestURL = request.getRequestURL().toString();
|
||||
if (!requestURI.startsWith(EurekaConstants.DEFAULT_PREFIX + "/v2")) {
|
||||
if (!requestURI.startsWith(EurekaConstants.DEFAULT_PREFIX + "/v2")
|
||||
// don't forward static requests (images, js, etc...) to /v2
|
||||
&& !staticPattern.matcher(requestURI).matches()) {
|
||||
|
||||
String updatedPath = EurekaConstants.DEFAULT_PREFIX + "/v2"
|
||||
+ requestURI.substring(EurekaConstants.DEFAULT_PREFIX.length());
|
||||
@@ -297,8 +309,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
// Construct the Jersey ResourceConfig
|
||||
ResourceConfig rc = new ResourceConfig(classes).property(
|
||||
// Skip static content used by the webapp
|
||||
ServletProperties.FILTER_STATIC_CONTENT_REGEX,
|
||||
EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");
|
||||
ServletProperties.FILTER_STATIC_CONTENT_REGEX, EurekaConstants.DEFAULT_PREFIX + STATIC_CONTENT_PATTERN);
|
||||
|
||||
rc.register(new ContainerLifecycleListener() {
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
@@ -71,7 +70,6 @@ class ApplicationContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/css/wro.css", String.class);
|
||||
@@ -79,7 +77,6 @@ class ApplicationContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/js/wro.js", String.class);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -64,7 +63,6 @@ class ApplicationDashboardPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/css/wro.css", String.class);
|
||||
@@ -72,7 +70,6 @@ class ApplicationDashboardPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/js/wro.js", String.class);
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
@@ -71,7 +70,6 @@ class ApplicationServletPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/css/wro.css", String.class);
|
||||
@@ -79,7 +77,6 @@ class ApplicationServletPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME 4.0
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/js/wro.js", String.class);
|
||||
|
||||
Reference in New Issue
Block a user