mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Javalin v5 bump (#930)
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
package org.photonvision.server;
|
||||
|
||||
import io.javalin.Javalin;
|
||||
import io.javalin.http.staticfiles.Location;
|
||||
import io.javalin.plugin.bundled.CorsPluginConfig;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.StringJoiner;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
@@ -27,45 +28,45 @@ public class Server {
|
||||
private static final Logger logger = new Logger(Server.class, LogGroup.WebServer);
|
||||
|
||||
public static void start(int port) {
|
||||
Javalin app =
|
||||
var app =
|
||||
Javalin.create(
|
||||
config -> {
|
||||
config.showJavalinBanner = false;
|
||||
config.addStaticFiles("web", Location.CLASSPATH);
|
||||
config.enableCorsForAllOrigins();
|
||||
javalinConfig -> {
|
||||
javalinConfig.showJavalinBanner = false;
|
||||
javalinConfig.staticFiles.add("web");
|
||||
javalinConfig.plugins.enableCors(
|
||||
corsContainer -> {
|
||||
corsContainer.add(CorsPluginConfig::anyHost);
|
||||
});
|
||||
|
||||
config.requestLogger(
|
||||
javalinConfig.requestLogger.http(
|
||||
(ctx, ms) -> {
|
||||
StringJoiner joiner =
|
||||
new StringJoiner(" ")
|
||||
.add("Handled HTTP request of type")
|
||||
.add(ctx.req.getMethod())
|
||||
.add(ctx.req().getMethod())
|
||||
.add("from endpoint")
|
||||
.add(ctx.path())
|
||||
.add("for host")
|
||||
.add(ctx.req.getRemoteHost())
|
||||
.add(ctx.req().getRemoteHost())
|
||||
.add("in")
|
||||
.add(ms.toString())
|
||||
.add("ms");
|
||||
|
||||
logger.debug(joiner.toString());
|
||||
});
|
||||
|
||||
config.wsLogger(
|
||||
ws ->
|
||||
ws.onMessage(
|
||||
ctx -> logger.debug("Got WebSockets message: " + ctx.message())));
|
||||
|
||||
config.wsLogger(
|
||||
ws ->
|
||||
ws.onBinaryMessage(
|
||||
ctx ->
|
||||
logger.trace(
|
||||
() -> {
|
||||
var insa = ctx.session.getRemote().getInetSocketAddress();
|
||||
var host = insa.getAddress().toString() + ":" + insa.getPort();
|
||||
return "Got WebSockets binary message from host " + host;
|
||||
})));
|
||||
javalinConfig.requestLogger.ws(
|
||||
ws -> {
|
||||
ws.onMessage(ctx -> logger.debug("Got WebSockets message: " + ctx.message()));
|
||||
ws.onBinaryMessage(
|
||||
ctx ->
|
||||
logger.trace(
|
||||
() -> {
|
||||
var remote = (InetSocketAddress) ctx.session.getRemoteAddress();
|
||||
var host =
|
||||
remote.getAddress().toString() + ":" + remote.getPort();
|
||||
return "Got WebSockets binary message from host: " + host;
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
/*Web Socket Events for Data Exchange */
|
||||
|
||||
Reference in New Issue
Block a user