Skip to content

Commit

Permalink
[backend] Handle back-end routes (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois authored and richard-julien committed Dec 28, 2023
1 parent dd4c55b commit 153cbc9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions openex-api/src/main/java/io/openex/rest/HomeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Expand All @@ -32,19 +31,19 @@ private static String readResourceAsString(Resource resource) {
@Value("${server.servlet.context-path}")
private String contextPath;

@GetMapping(path = {"/", "/admin/**", "/players/**"}, produces = MediaType.TEXT_HTML_VALUE)
@GetMapping(path = {"/", "/{path:^(?!api$|login$|logout$|oauth2$|saml2$|static$).*$}/**"}, produces = MediaType.TEXT_HTML_VALUE)
public ResponseEntity<String> home() {
ClassPathResource classPathResource = new ClassPathResource("/build/index.html");
String index = readResourceAsString(classPathResource);
String basePath = contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
String basePath = this.contextPath.endsWith("/") ? this.contextPath.substring(0, this.contextPath.length() - 1) : this.contextPath;
String newIndex = index.
replaceAll("%APP_TITLE%", "OpenEx - Crisis Exercises and Adversary Simulation Platform").
replaceAll("%APP_DESCRIPTION%", "OpenEx is an open source platform allowing organizations to plan, schedule and conduct crisis exercises as well as adversary simulation campaign.").
replaceAll("%APP_FAVICON%", basePath + "/static/ext/favicon.png").
replaceAll("%APP_MANIFEST%", basePath + "/static/ext/manifest.json").
replaceAll("%BASE_PATH%", basePath);
replaceAll("%APP_TITLE%", "OpenEx - Crisis Exercises and Adversary Simulation Platform").
replaceAll("%APP_DESCRIPTION%", "OpenEx is an open source platform allowing organizations to plan, schedule and conduct crisis exercises as well as adversary simulation campaign.").
replaceAll("%APP_FAVICON%", basePath + "/static/ext/favicon.png").
replaceAll("%APP_MANIFEST%", basePath + "/static/ext/manifest.json").
replaceAll("%BASE_PATH%", basePath);
return ResponseEntity.ok()
.header(HttpHeaders.CACHE_CONTROL, "no-cache")
.body(newIndex);
.header(HttpHeaders.CACHE_CONTROL, "no-cache")
.body(newIndex);
}
}

0 comments on commit 153cbc9

Please sign in to comment.