Skip to content

Commit

Permalink
Added javalin web server
Browse files Browse the repository at this point in the history
  • Loading branch information
mpulte committed Jan 28, 2024
1 parent c990ff9 commit de5e693
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/team1701/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/ts/dashboard/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down

0 comments on commit de5e693

Please sign in to comment.