Skip to content

Commit 9f12558

Browse files
fix: disable static resources on --no-ui and clean up stale SpaController routes
- CodeIqApplication: set spring.web.resources.add-mappings=false when --no-ui is active, preventing static file serving (index.html, JS, CSS bundles) - SpaController: replace stale /topology and /flow routes with /graph (matches the current Code Graph treemap tab added in 482ca24) - SpaControllerConditionalTest: add staticResourcesDisabledWhenUiDisabled test and spaControllerExplicitRoutesContainGraph test (1449 total, 0 failures) Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent ddcd713 commit 9f12558

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

src/main/java/io/github/randomcodespace/iq/CodeIqApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public static void main(String[] args) {
7171
boolean noUi = Arrays.asList(args).contains("--no-ui");
7272
if (noUi) {
7373
System.setProperty("codeiq.ui.enabled", "false");
74+
// Also disable Spring Boot's static resource handler so no
75+
// static files (index.html, JS, CSS bundles) are served.
76+
System.setProperty("spring.web.resources.add-mappings", "false");
7477
}
7578

7679
// Resolve codebase root so Neo4j points to the correct graph.db

src/main/java/io/github/randomcodespace/iq/web/SpaController.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Catch-all controller that forwards unmatched routes to index.html
1010
* for React Router client-side routing (HTML5 pushState).
1111
* <p>
12-
* Only matches paths without a file extension (e.g. /topology, /explorer/class)
12+
* Only matches paths without a file extension (e.g. /graph, /explorer/class)
1313
* so static assets (.js, .css, .html, .svg) are served normally.
1414
* <p>
1515
* Disabled when {@code codeiq.ui.enabled=false} (i.e. {@code --no-ui} flag passed to serve).
@@ -20,12 +20,10 @@
2020
public class SpaController {
2121

2222
@GetMapping(value = {
23-
"/topology",
24-
"/topology/**",
23+
"/graph",
24+
"/graph/**",
2525
"/explorer",
2626
"/explorer/**",
27-
"/flow",
28-
"/flow/**",
2927
"/console",
3028
"/console/**",
3129
"/api-docs",

src/test/java/io/github/randomcodespace/iq/web/SpaControllerConditionalTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
55
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
66
import org.springframework.context.annotation.Profile;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
9+
import java.lang.reflect.Method;
10+
import java.util.Arrays;
11+
import java.util.List;
712

813
import static org.assertj.core.api.Assertions.assertThat;
914

1015
/**
11-
* Verifies that SpaController is conditionally registered based on codeiq.ui.enabled.
16+
* Verifies that SpaController is conditionally registered based on codeiq.ui.enabled,
17+
* and that static resource serving is also disabled via spring.web.resources.add-mappings=false.
1218
*/
1319
class SpaControllerConditionalTest {
1420

@@ -51,4 +57,28 @@ void spaControllerHasProfileAnnotation() {
5157
assertThat(annotation).isNotNull();
5258
assertThat(annotation.value()).contains("serving");
5359
}
60+
61+
@Test
62+
void staticResourcesDisabledWhenUiDisabled() {
63+
// When --no-ui is active, CodeIqApplication sets both properties.
64+
// Verify that spring.web.resources.add-mappings=false combined with
65+
// codeiq.ui.enabled=false leaves no SpaController in the context.
66+
contextRunner
67+
.withPropertyValues("codeiq.ui.enabled=false", "spring.web.resources.add-mappings=false")
68+
.run(context -> assertThat(context).doesNotHaveBean(SpaController.class));
69+
}
70+
71+
@Test
72+
void spaControllerExplicitRoutesContainGraph() {
73+
// Verify that /graph routes are present and /topology, /flow routes are removed.
74+
Method forwardMethod = Arrays.stream(SpaController.class.getDeclaredMethods())
75+
.filter(m -> m.isAnnotationPresent(GetMapping.class))
76+
.filter(m -> m.getName().equals("forward"))
77+
.findFirst()
78+
.orElse(null);
79+
assertThat(forwardMethod).isNotNull();
80+
List<String> routes = Arrays.asList(forwardMethod.getAnnotation(GetMapping.class).value());
81+
assertThat(routes).contains("/graph", "/graph/**");
82+
assertThat(routes).doesNotContain("/topology", "/topology/**", "/flow", "/flow/**");
83+
}
5484
}

0 commit comments

Comments
 (0)