From 068081be1f0913f0727afed00878f6e6478e0b14 Mon Sep 17 00:00:00 2001 From: Dom Eori <4j6dq2zi8@relay.firefox.com> Date: Mon, 14 Feb 2022 22:23:46 +0900 Subject: [PATCH] [api] Add internal aquaviewer serving feature --- .../samnyan/aqua/api/config/WebConfig.java | 38 +++++++++++++++++++ .../aqua/sega/allnet/AllNetController.java | 5 ++- .../samnyan/aqua/spring/util/AutoChecker.java | 2 + 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/main/java/icu/samnyan/aqua/api/config/WebConfig.java diff --git a/src/main/java/icu/samnyan/aqua/api/config/WebConfig.java b/src/main/java/icu/samnyan/aqua/api/config/WebConfig.java new file mode 100644 index 00000000..b23b8660 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/api/config/WebConfig.java @@ -0,0 +1,38 @@ +package icu.samnyan.aqua.api.config; + +import java.io.IOException; + +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.resource.PathResourceResolver; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + + // Static assets (images), this priority must be higher than routes + registry.addResourceHandler("/web/assets/**") + .addResourceLocations("file:web/assets/") + .setCachePeriod(10) + .resourceChain(true) + .addResolver(new PathResourceResolver()); + + // For angularjs html5 routes + registry.addResourceHandler("/web/**", "/web/", "/web") + .addResourceLocations("file:web/") + .setCachePeriod(10) + .resourceChain(true) + .addResolver(new PathResourceResolver() { + @Override + protected Resource getResource(String resourcePath, Resource location) throws IOException { + Resource requestedResource = location.createRelative(resourcePath); + return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new FileSystemResource("web/index.html"); + } + }); + } +} \ No newline at end of file diff --git a/src/main/java/icu/samnyan/aqua/sega/allnet/AllNetController.java b/src/main/java/icu/samnyan/aqua/sega/allnet/AllNetController.java index e818af91..0217af29 100644 --- a/src/main/java/icu/samnyan/aqua/sega/allnet/AllNetController.java +++ b/src/main/java/icu/samnyan/aqua/sega/allnet/AllNetController.java @@ -19,6 +19,7 @@ import java.time.LocalDateTime; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import static icu.samnyan.aqua.sega.util.AquaConst.DEFAULT_KEYCHIP_ID; @@ -41,8 +42,8 @@ public class AllNetController { } @GetMapping("/") - public String root() { - return "Server running"; + public void root(HttpServletResponse response) throws IOException { + response.sendRedirect("web"); } @GetMapping("/sys/test") diff --git a/src/main/java/icu/samnyan/aqua/spring/util/AutoChecker.java b/src/main/java/icu/samnyan/aqua/spring/util/AutoChecker.java index e053abc1..6dce13ad 100644 --- a/src/main/java/icu/samnyan/aqua/spring/util/AutoChecker.java +++ b/src/main/java/icu/samnyan/aqua/spring/util/AutoChecker.java @@ -59,6 +59,8 @@ public class AutoChecker { "╚═╝ ╚═╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝\n" + " "); + System.out.println("Aqua viewer at http://localhost/web/\n"); + System.out.println("======= Self test running ======="); // Check aimedb System.out.print(" AimeDB : ");