mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-22 03:45:10 +01:00
Upgrade Javalin to 5.5.0 & Fix project warnings
This commit is contained in:
@@ -11,6 +11,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
@@ -28,22 +29,25 @@ public final class HttpServer {
|
||||
public HttpServer() {
|
||||
this.javalin = Javalin.create(config -> {
|
||||
// Set the Javalin HTTP server.
|
||||
config.server(HttpServer::createServer);
|
||||
config.jetty.server(HttpServer::createServer);
|
||||
|
||||
// Configure encryption/HTTPS/SSL.
|
||||
config.enforceSsl = HTTP_ENCRYPTION.useEncryption;
|
||||
if (HTTP_ENCRYPTION.useEncryption)
|
||||
config.plugins.enableSslRedirects();
|
||||
|
||||
// Configure HTTP policies.
|
||||
if (HTTP_POLICIES.cors.enabled) {
|
||||
var allowedOrigins = HTTP_POLICIES.cors.allowedOrigins;
|
||||
if (allowedOrigins.length > 0)
|
||||
config.enableCorsForOrigin(allowedOrigins);
|
||||
else config.enableCorsForAllOrigins();
|
||||
config.plugins.enableCors(cors -> cors.add(corsConfig -> {
|
||||
if (allowedOrigins.length > 0)
|
||||
corsConfig.allowHost(Arrays.toString(allowedOrigins));
|
||||
else corsConfig.anyHost();
|
||||
}));
|
||||
}
|
||||
|
||||
// Configure debug logging.
|
||||
if (DISPATCH_INFO.logRequests == ServerDebugMode.ALL)
|
||||
config.enableDevLogging();
|
||||
config.plugins.enableDevLogging();
|
||||
|
||||
// Static files should be added like this https://javalin.io/documentation#static-files
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user