edited stuff (#50)

This commit is contained in:
Valentin Heiserer
2024-04-23 23:27:01 +02:00
committed by GitHub
parent b8b89ee696
commit 2e5a42b6d3
8 changed files with 62 additions and 47 deletions

View File

@@ -48,13 +48,15 @@ public class BackendServer implements MessageSender {
// Configure CORS settings
configureCors(context);
URL webContentUrl = getClass().getClassLoader().getResource("web-content");
if (webContentUrl == null) {
throw new RuntimeException("Unable to find 'web-content' directory");
if (openFrontend) {
URL webContentUrl = getClass().getClassLoader().getResource("web-content");
if (webContentUrl == null) {
throw new RuntimeException("Unable to find 'web-content' directory");
}
String webContentPath = webContentUrl.toExternalForm();
context.setResourceBase(webContentPath);
context.addServlet(new ServletHolder("frontend", DefaultServlet.class), "/");
}
String webContentPath = webContentUrl.toExternalForm();
context.setResourceBase(webContentPath);
context.addServlet(new ServletHolder("frontend", DefaultServlet.class), "/");
// Configure specific websocket behavior
JettyWebSocketServletContainerInitializer.configure(

View File

@@ -2,7 +2,6 @@ package org.schafkopf;
import com.google.gson.JsonObject;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
@@ -31,20 +30,11 @@ public class DedicatedServerConnection implements MessageSender {
* Class that represents one Frontend Connection.
*/
public DedicatedServerConnection(String address, MessageListener messageListener) {
URI uri = null;
try {
uri = new URI(address);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
this.messageListener = messageListener;
this.closeLatch = new CountDownLatch(1);
this.connectionLatch = new CountDownLatch(1);
String host = uri.getHost();
int port = uri.getPort();
connect("ws://" + host + ":" + port);
connect("ws://" + address);
try {
connectionLatch.await(); // Wait until the connection is established
} catch (InterruptedException e) {