diff --git a/src/buttondevteam/website/page/Page.java b/src/buttondevteam/website/page/Page.java index 66633f8..362408a 100644 --- a/src/buttondevteam/website/page/Page.java +++ b/src/buttondevteam/website/page/Page.java @@ -17,28 +17,46 @@ public abstract class Page implements HttpHandler { @Override public void handle(HttpExchange exchange) { - try { - exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "https://tbmcplugins.github.io"); - if (exchange.getRequestURI().getPath().equals("/" + GetName())) - IOHelper.SendResponse(handlePage(exchange)); - else { - IOHelper.SendResponse(404, "404 Not found", exchange); - } - } catch (Exception e) { - TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e); + + //Creates a new thread to handle the request + Handler handler = new Handler(exchange); + handler.start(); + } + + class Handler extends Thread{ + + HttpExchange exchange; + + public Handler(HttpExchange exchange){ + this.exchange = exchange; + } + + @Override + public void run(){ try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream str = new PrintStream(baos); - str.print("
"); - e.printStackTrace(str); - str.print(""); - IOHelper.SendResponse(500, baos.toString("UTF-8"), exchange); - } catch (Exception e1) { - e1.printStackTrace(); + exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "https://tbmcplugins.github.io"); + if (exchange.getRequestURI().getPath().equals("/" + GetName())) + IOHelper.SendResponse(handlePage(exchange)); + else { + IOHelper.SendResponse(404, "404 Not found", exchange); + } + } catch (Exception e) { + TBMCCoreAPI.SendException("Internal Server Error in ButtonWebsiteModule!", e); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream str = new PrintStream(baos); + str.print("
"); + e.printStackTrace(str); + str.print(""); + IOHelper.SendResponse(500, baos.toString("UTF-8"), exchange); + } catch (Exception e1) { + e1.printStackTrace(); + } } } } - + + /** * The main logic of the endpoint. Use IOHelper to retrieve the message sent and other things. */