Commit 55793867 authored by Muhammad Eko Prasetyo's avatar Muhammad Eko Prasetyo Committed by GitHub
Browse files

Fix DispatchHttpJson handler and add setHttpServer because Express doesn't...

Fix DispatchHttpJson handler and add setHttpServer because Express doesn't support removing defined route. (#388)
parent 1908a9fd
...@@ -36,7 +36,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler { ...@@ -36,7 +36,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler {
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
if(Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) { if(Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) {
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: ", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") ? "(MISSING)" : "")); Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: ", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") ? "(MISSING)" : ""));
res.send(response.getBytes());
} }
res.send(response);
} }
} }
...@@ -50,6 +50,12 @@ public final class DispatchServer { ...@@ -50,6 +50,12 @@ public final class DispatchServer {
return httpServer; return httpServer;
} }
public void setHttpServer(Express httpServer) {
this.httpServer.stop();
this.httpServer = httpServer;
this.httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port);
}
public Gson getGsonFactory() { public Gson getGsonFactory() {
return gson; return gson;
} }
...@@ -271,12 +277,12 @@ public final class DispatchServer { ...@@ -271,12 +277,12 @@ public final class DispatchServer {
}); });
// Login // Login
httpServer.post("/hk4e_global/mdk/shield/api/login", (req, res) -> { httpServer.post("/hk4e_global/mdk/shield/api/login", (req, res) -> {
// Get post data // Get post data
LoginAccountRequestJson requestData = null; LoginAccountRequestJson requestData = null;
try { try {
String body = req.ctx().body(); String body = req.ctx().body();
Grasscutter.getLogger().info(body);
requestData = getGsonFactory().fromJson(body, LoginAccountRequestJson.class); requestData = getGsonFactory().fromJson(body, LoginAccountRequestJson.class);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment