mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Only Serve API if using WebServer on Bungee
This commit is contained in:
parent
e048fb6d64
commit
7c154bbb5e
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Licence is provided in the jar as license.yml also here:
|
||||||
|
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||||
|
*/
|
||||||
|
package main.java.com.djrapitops.plan.systems.webserver;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
|
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||||
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HttpHandler for webserver request management.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class APIRequestHandler implements HttpHandler {
|
||||||
|
|
||||||
|
private final APIResponseHandler responseHandler;
|
||||||
|
|
||||||
|
APIRequestHandler(WebAPIManager webAPI) {
|
||||||
|
responseHandler = new APIResponseHandler(webAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(HttpExchange exchange) throws IOException {
|
||||||
|
Request request = new Request(exchange);
|
||||||
|
try {
|
||||||
|
Response response = responseHandler.getAPIResponse(request);
|
||||||
|
response.send(exchange);
|
||||||
|
} finally {
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -91,7 +91,11 @@ public class WebServer {
|
|||||||
server = HttpServer.create(new InetSocketAddress(port), 10);
|
server = HttpServer.create(new InetSocketAddress(port), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.createContext("/", new RequestHandler(plugin, this));
|
if (plugin.getInfoManager().isUsingBungeeWebServer()) {
|
||||||
|
server.createContext("/", new APIRequestHandler(getWebAPI()));
|
||||||
|
} else {
|
||||||
|
server.createContext("/", new RequestHandler(plugin, this));
|
||||||
|
}
|
||||||
|
|
||||||
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
|
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
|
||||||
server.start();
|
server.start();
|
||||||
|
Loading…
Reference in New Issue
Block a user