From 63a37acc1b46d44bec29f9bd4485fdf648436a53 Mon Sep 17 00:00:00 2001 From: Muhammad Eko Prasetyo Date: Sat, 7 May 2022 03:23:26 +0700 Subject: [PATCH] add config option to enable cors for dispatchserver (#579) --- src/main/java/emu/grasscutter/Config.java | 2 ++ .../java/emu/grasscutter/server/dispatch/DispatchServer.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index e7536b588..c911a1cf0 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -41,6 +41,8 @@ public final class Config { public String KeystorePassword = "123456"; public Boolean UseSSL = true; public Boolean FrontHTTPS = true; + public Boolean CORS = false; + public String[] CORSAllowedOrigins = new String[] { "*" }; public boolean AutomaticallyCreateAccounts = false; public String[] defaultPermissions = new String[] { "" }; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 85f02a36d..737193fbd 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -245,8 +245,11 @@ public final class DispatchServer { if(Grasscutter.getConfig().DebugMode == ServerDebugMode.ALL) { config.enableDevLogging(); } + if (Grasscutter.getConfig().getDispatchOptions().CORS){ + if (Grasscutter.getConfig().getDispatchOptions().CORSAllowedOrigins.length > 0) config.enableCorsForOrigin(Grasscutter.getConfig().getDispatchOptions().CORSAllowedOrigins); + else config.enableCorsForAllOrigins(); + } }); - httpServer.get("/", (req, res) -> res.send(Grasscutter.getLanguage().Welcome)); httpServer.raw().error(404, ctx -> {