From 2a3248435c37bd742beedcaba77648445958860a Mon Sep 17 00:00:00 2001 From: djmil Date: Fri, 1 Dec 2023 21:24:36 +0100 Subject: [PATCH] SpringBoot serving React * build React release bundle npm run build * copy build directory to backend/src/main/resources/static * enjoy husle free deployment --- .../cordacheckers/ReactAppController.java | 20 +++++++++++++++++++ .../src/main/resources/application.properties | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/djmil/cordacheckers/ReactAppController.java diff --git a/backend/src/main/java/djmil/cordacheckers/ReactAppController.java b/backend/src/main/java/djmil/cordacheckers/ReactAppController.java new file mode 100644 index 0000000..d030f23 --- /dev/null +++ b/backend/src/main/java/djmil/cordacheckers/ReactAppController.java @@ -0,0 +1,20 @@ +package djmil.cordacheckers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; + +import jakarta.servlet.http.HttpServletRequest; + +@Controller +public class ReactAppController { + // This controller simply redirects all UI related routes + // to index.html, allowing react and react-router to work its magic + + @GetMapping(value = { "/", "/games/*","/about","/leaderboard" }) + @PutMapping("/error") + public String getIndex(HttpServletRequest inRequest) { + return "/index.html"; + } + +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index aa7972a..9c12aa8 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -8,4 +8,6 @@ corda.root.login=admin corda.root.passw=admin corda.client.maxPollAttempts=30 -server.port=8081 \ No newline at end of file +server.port=8081 + +#logging.level.org.springframework.web=DEBUG \ No newline at end of file