[api] Add option to disable aquaviewer serving

This commit is contained in:
Dom Eori 2022-06-19 18:19:16 +09:00
parent 19921f4702
commit 3445d073a5
4 changed files with 42 additions and 20 deletions

View File

@ -19,6 +19,10 @@ billing.server.port=8443
## The game rely on 80 port for boot up command ## The game rely on 80 port for boot up command
server.port=80 server.port=80
## Static file server
## This is used to server static files in /web/ directory, which is Aquaviewer
aquaviewer.server.enable=true
## Chunithm ## Chunithm
## This enables team function if you set team name here. Leave this blank to disable it. ## This enables team function if you set team name here. Leave this blank to disable it.
game.chunithm.team-name= game.chunithm.team-name=

View File

@ -2,6 +2,7 @@ package icu.samnyan.aqua.api.config;
import java.io.IOException; import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -12,27 +13,37 @@ import org.springframework.web.servlet.resource.PathResourceResolver;
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
private final boolean AQUAVIEWER_ENABLED;
public WebConfig(@Value("${aquaviewer.server.enable:true}") boolean AQUAVIEWER_ENABLED) {
this.AQUAVIEWER_ENABLED = AQUAVIEWER_ENABLED;
}
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Static assets (images), this priority must be higher than routes if (AQUAVIEWER_ENABLED) {
registry.addResourceHandler("/web/assets/**") // Static assets (images), this priority must be higher than routes
.addResourceLocations("file:web/assets/") registry.addResourceHandler("/web/assets/**")
.setCachePeriod(10) .addResourceLocations("file:web/assets/")
.resourceChain(true) .setCachePeriod(10)
.addResolver(new PathResourceResolver()); .resourceChain(true)
.addResolver(new PathResourceResolver());
// For angularjs html5 routes // For angularjs html5 routes
registry.addResourceHandler("/web/**", "/web/", "/web") registry.addResourceHandler("/web/**", "/web/", "/web")
.addResourceLocations("file:web/") .addResourceLocations("file:web/")
.setCachePeriod(10) .setCachePeriod(10)
.resourceChain(true) .resourceChain(true)
.addResolver(new PathResourceResolver() { .addResolver(new PathResourceResolver() {
@Override @Override
protected Resource getResource(String resourcePath, Resource location) throws IOException { protected Resource getResource(String resourcePath, Resource location) throws IOException {
Resource requestedResource = location.createRelative(resourcePath); Resource requestedResource = location.createRelative(resourcePath);
return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new FileSystemResource("web/index.html"); return requestedResource.exists() && requestedResource.isReadable() ? requestedResource
} : new FileSystemResource("web/index.html");
}); }
});
}
} }
} }

View File

@ -29,6 +29,7 @@ public class AutoChecker {
private final boolean AIMEDB_ENABLED; private final boolean AIMEDB_ENABLED;
private final boolean BILLING_ENABLED; private final boolean BILLING_ENABLED;
private final int BILLING_PORT; private final int BILLING_PORT;
private final boolean AQUAVIEWER_ENABLED;
public AutoChecker( public AutoChecker(
@Value("${server.host:}") String SERVER_PORT, @Value("${server.host:}") String SERVER_PORT,
@ -38,7 +39,8 @@ public class AutoChecker {
@Value("${aimedb.server.port}") int AIMEDB_PORT, @Value("${aimedb.server.port}") int AIMEDB_PORT,
@Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED, @Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED,
@Value("${billing.server.port}") int BILLING_PORT, @Value("${billing.server.port}") int BILLING_PORT,
@Value("${billing.server.enable}") boolean BILLING_ENABLED) { @Value("${billing.server.enable}") boolean BILLING_ENABLED,
@Value("${aquaviewer.server.enable:true}") boolean AQUAVIEWER_ENABLED) {
this.SERVER_PORT = SERVER_PORT; this.SERVER_PORT = SERVER_PORT;
this.ALLNET_HOST_OVERRIDE = ALLNET_HOST; this.ALLNET_HOST_OVERRIDE = ALLNET_HOST;
this.ALLNET_PORT_OVERRIDE = ALLNET_PORT; this.ALLNET_PORT_OVERRIDE = ALLNET_PORT;
@ -47,6 +49,7 @@ public class AutoChecker {
this.AIMEDB_ENABLED = AIMEDB_ENABLED; this.AIMEDB_ENABLED = AIMEDB_ENABLED;
this.BILLING_PORT = BILLING_PORT; this.BILLING_PORT = BILLING_PORT;
this.BILLING_ENABLED = BILLING_ENABLED; this.BILLING_ENABLED = BILLING_ENABLED;
this.AQUAVIEWER_ENABLED = AQUAVIEWER_ENABLED;
} }
public void check() { public void check() {
@ -59,7 +62,9 @@ public class AutoChecker {
"╚═╝ ╚═╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝\n" + "╚═╝ ╚═╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝\n" +
" "); " ");
System.out.println("Aqua viewer at http://localhost/web/\n"); if (AQUAVIEWER_ENABLED) {
System.out.println("Aqua viewer at http://localhost/web/\n");
}
System.out.println("======= Self test running ======="); System.out.println("======= Self test running =======");
// Check aimedb // Check aimedb

View File

@ -7,6 +7,8 @@ aimedb.server.port=22345
billing.server.enable=true billing.server.enable=true
billing.server.port=8443 billing.server.port=8443
aquaviewer.server.enable=true
server.port=80 server.port=80
spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-file-size=10MB