add config option to enable cors for dispatchserver (#579)

This commit is contained in:
Muhammad Eko Prasetyo 2022-05-07 03:23:26 +07:00 committed by GitHub
parent da99140d20
commit 63a37acc1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -41,6 +41,8 @@ public final class Config {
public String KeystorePassword = "123456"; public String KeystorePassword = "123456";
public Boolean UseSSL = true; public Boolean UseSSL = true;
public Boolean FrontHTTPS = true; public Boolean FrontHTTPS = true;
public Boolean CORS = false;
public String[] CORSAllowedOrigins = new String[] { "*" };
public boolean AutomaticallyCreateAccounts = false; public boolean AutomaticallyCreateAccounts = false;
public String[] defaultPermissions = new String[] { "" }; public String[] defaultPermissions = new String[] { "" };

View File

@ -245,8 +245,11 @@ public final class DispatchServer {
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.ALL) { if(Grasscutter.getConfig().DebugMode == ServerDebugMode.ALL) {
config.enableDevLogging(); 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.get("/", (req, res) -> res.send(Grasscutter.getLanguage().Welcome));
httpServer.raw().error(404, ctx -> { httpServer.raw().error(404, ctx -> {