From de5e6939a8798e9c66474cd1374e385179921659 Mon Sep 17 00:00:00 2001 From: Marc Pulte Date: Sun, 28 Jan 2024 16:41:43 -0500 Subject: [PATCH] Added javalin web server --- build.gradle | 2 ++ src/main/java/com/team1701/robot/Robot.java | 15 +++++++++++++++ src/main/ts/dashboard/package.json | 2 +- src/main/ts/dashboard/vite.config.ts | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 42b9ee3f..7fc0df07 100644 --- a/build.gradle +++ b/build.gradle @@ -96,6 +96,8 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation "io.javalin:javalin:6.0.0" + def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text) annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version" } diff --git a/src/main/java/com/team1701/robot/Robot.java b/src/main/java/com/team1701/robot/Robot.java index 8f6de8c4..48a41cff 100644 --- a/src/main/java/com/team1701/robot/Robot.java +++ b/src/main/java/com/team1701/robot/Robot.java @@ -4,13 +4,17 @@ package com.team1701.robot; +import java.nio.file.Paths; import java.util.Optional; import com.team1701.robot.Configuration.Mode; import edu.wpi.first.hal.AllianceStationID; +import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.simulation.DriverStationSim; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; +import io.javalin.Javalin; +import io.javalin.http.staticfiles.Location; import org.littletonrobotics.junction.LogFileUtil; import org.littletonrobotics.junction.LoggedRobot; import org.littletonrobotics.junction.Logger; @@ -91,7 +95,18 @@ private void initializeAdvantageKit() { // Start AdvantageKit logger setUseTiming(Configuration.getMode() != Configuration.Mode.REPLAY); Logger.start(); + + // Build robot container mRobotContainer = new RobotContainer(); + + // Launch web server + Javalin.create(config -> { + config.staticFiles.add( + Paths.get(Filesystem.getDeployDirectory().getAbsolutePath(), "web") + .toString(), + Location.EXTERNAL); + }) + .start(5800); } @Override diff --git a/src/main/ts/dashboard/package.json b/src/main/ts/dashboard/package.json index eab07017..fc14410e 100644 --- a/src/main/ts/dashboard/package.json +++ b/src/main/ts/dashboard/package.json @@ -9,7 +9,7 @@ "lint:ci": "eslint .", "dev": "vite", "build": "vite build", - "build:deploy": "DASHBOARD_OUT_DIR='../../deploy/web/dashboard' vite build", + "build:deploy": "DASHBOARD_BASE='dashboard' DASHBOARD_OUT_DIR='../../deploy/web/dashboard' vite build", "watch": "vite build --watch", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json" diff --git a/src/main/ts/dashboard/vite.config.ts b/src/main/ts/dashboard/vite.config.ts index b1cff04a..00b5577e 100644 --- a/src/main/ts/dashboard/vite.config.ts +++ b/src/main/ts/dashboard/vite.config.ts @@ -1,8 +1,10 @@ import { defineConfig } from 'vite'; export default defineConfig({ + base: process.env.DASHBOARD_BASE ?? '/', build: { outDir: process.env.DASHBOARD_OUT_DIR ?? 'dist', + emptyOutDir: true, chunkSizeWarningLimit: 1000, rollupOptions: { output: {