浏览代码

#581 Skip trailing slash (#586)

German Osin 4 年之前
父节点
当前提交
1a916ab247

+ 1 - 0
docker/kafka-ui-sasl.yaml

@@ -12,6 +12,7 @@ services:
       - kafka
     environment:
       KAFKA_CLUSTERS_0_NAME: local
+#      SERVER_SERVLET_CONTEXT_PATH: "/kafkaui"
       KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092
       KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181
       KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: SASL_PLAINTEXT

+ 4 - 3
kafka-ui-api/src/main/java/com/provectus/kafka/ui/config/CustomWebFilter.java

@@ -1,5 +1,6 @@
 package com.provectus.kafka.ui.config;
 
+import java.util.Optional;
 import org.springframework.boot.autoconfigure.web.ServerProperties;
 import org.springframework.stereotype.Component;
 import org.springframework.web.server.ServerWebExchange;
@@ -22,13 +23,13 @@ public class CustomWebFilter implements WebFilter {
     String contextPath = serverProperties.getServlet().getContextPath() != null 
         ? serverProperties.getServlet().getContextPath() : "";
 
-    if (exchange.getRequest().getURI().getPath().equals(contextPath + "/")
-        || exchange.getRequest().getURI().getPath().startsWith(contextPath + "/ui")) {
+    final String path = exchange.getRequest().getURI().getPath().replaceAll("/$", "");
+    if (path.equals(contextPath) || path.startsWith(contextPath + "/ui")) {
       return chain.filter(
           exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build())
               .build()
       );
-    } else if (exchange.getRequest().getURI().getPath().startsWith(contextPath)) {
+    } else if (path.startsWith(contextPath)) {
       return chain.filter(
           exchange.mutate().request(exchange.getRequest().mutate().contextPath(contextPath).build())
               .build()