From 227043b918215b0e1b66c8bb3d94bf1354fc2b47 Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Thu, 9 Jan 2025 23:00:17 +0700 Subject: [PATCH] BE: Auth: Fix startup error on missing (non-prod profile) index.html --- .../main/java/io/kafbat/ui/util/StaticFileWebFilter.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/src/main/java/io/kafbat/ui/util/StaticFileWebFilter.java b/api/src/main/java/io/kafbat/ui/util/StaticFileWebFilter.java index 1b74bd374..f76ffad6b 100644 --- a/api/src/main/java/io/kafbat/ui/util/StaticFileWebFilter.java +++ b/api/src/main/java/io/kafbat/ui/util/StaticFileWebFilter.java @@ -1,6 +1,7 @@ package io.kafbat.ui.util; import java.io.IOException; +import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.buffer.DataBufferFactory; @@ -15,6 +16,7 @@ import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; +@Slf4j public class StaticFileWebFilter implements WebFilter { private static final String INDEX_HTML = "/static/index.html"; @@ -29,6 +31,12 @@ public StaticFileWebFilter() { public StaticFileWebFilter(String path, ClassPathResource resource) { this.matcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, path); + if (!resource.exists()) { + log.warn("Resource [{}] does not exist. Frontend might not be available.", resource.getPath()); + contents = "Missing index.html. Make sure the app has been built with a correct (prod) profile."; + return; + } + try { this.contents = ResourceUtil.readAsString(resource); } catch (IOException e) {