From 1a916ab247e0f221fd8d0f967de3b1206add10b9 Mon Sep 17 00:00:00 2001 From: German Osin Date: Fri, 25 Jun 2021 15:39:07 +0300 Subject: [PATCH] #581 Skip trailing slash (#586) --- docker/kafka-ui-sasl.yaml | 1 + .../com/provectus/kafka/ui/config/CustomWebFilter.java | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docker/kafka-ui-sasl.yaml b/docker/kafka-ui-sasl.yaml index 87b1094be7..1c0312f11a 100644 --- a/docker/kafka-ui-sasl.yaml +++ b/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 diff --git a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/config/CustomWebFilter.java b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/config/CustomWebFilter.java index dfe9c4c13f..5efee1db8d 100644 --- a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/config/CustomWebFilter.java +++ b/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()