Compare commits

..

No commits in common. "1060d4d577994abc346821677e69b5a27002143e" and "abbb02729af0cc34baa929a78d6233284f1acd89" have entirely different histories.

7 changed files with 16 additions and 44 deletions

View file

@ -1,13 +1,3 @@
* *
!src/ !src/
!pom.xml !pom.xml
!ui/package*.json
!ui/postcss.config.js
!ui/tailwind.config.js
!ui/env.d..ts
!ui/vite.config.ts
!ui/tsconfig.json
!ui/tsconfig.node.json
!ui/index.html
!ui/public/
!ui/src/

View file

@ -1,4 +1,4 @@
# Stage 1: Build java application # Stage 1: Build the application
FROM docker.io/maven:3.9-eclipse-temurin-19 AS maven FROM docker.io/maven:3.9-eclipse-temurin-19 AS maven
WORKDIR /app WORKDIR /app
COPY pom.xml . COPY pom.xml .
@ -7,19 +7,9 @@ RUN mvn package
COPY src/ /app/src/ COPY src/ /app/src/
RUN mvn package RUN mvn package
# Stage 2: Build vuejs application # Stage 2: Create the jlink app
FROM docker.io/node:18-slim AS vuejs
WORKDIR /app
COPY ./ui/package* .
RUN npm ci
COPY ./ui .
RUN npm run build-only
# Stage 3: Create the jlink app
FROM docker.io/eclipse-temurin:19-jdk FROM docker.io/eclipse-temurin:19-jdk
WORKDIR /app WORKDIR /app
COPY --from=maven /app/target/dchat-*-fat.jar /app/dchat.jar COPY --from=maven /app/target/dchat-*-fat.jar /app/dchat.jar
COPY --from=vuejs /app/dist /app/ui/dist
EXPOSE 8080
CMD ["java", "--enable-preview", "-jar", "/app/dchat.jar"] CMD ["java", "--enable-preview", "-jar", "/app/dchat.jar"]

View file

@ -40,7 +40,7 @@
<dependency> <dependency>
<groupId>io.javalin</groupId> <groupId>io.javalin</groupId>
<artifactId>javalin</artifactId> <artifactId>javalin</artifactId>
<version>5.5.0</version> <version>5.4.2</version>
</dependency> </dependency>
<!-- logging --> <!-- logging -->
<dependency> <dependency>

View file

@ -39,7 +39,7 @@ public class Main {
System.exit(1); System.exit(1);
} }
String apiPortStr = System.getenv("API_PORT") != null ? System.getenv("API_PORT") : "8080"; String apiPortStr = System.getenv("PAI_PORT") != null ? System.getenv("API_PORT") : "8080";
int apiPort = Integer.parseInt(apiPortStr); int apiPort = Integer.parseInt(apiPortStr);
var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient()); var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient());

View file

@ -5,8 +5,8 @@ import de.hhhammer.dchat.db.UserDBService;
import de.hhhammer.dchat.web.server.ConfigCrudHandler; import de.hhhammer.dchat.web.server.ConfigCrudHandler;
import de.hhhammer.dchat.web.user.ConfigUserCrudHandler; import de.hhhammer.dchat.web.user.ConfigUserCrudHandler;
import io.javalin.Javalin; import io.javalin.Javalin;
import io.javalin.http.HandlerType;
import io.javalin.http.HttpStatus; import io.javalin.http.HttpStatus;
import io.javalin.http.staticfiles.Location;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,11 +32,6 @@ public class WebAPI implements Runnable {
config.plugins.enableDevLogging(); config.plugins.enableDevLogging();
config.http.prefer405over404 = true; // return 405 instead of 404 if path is mapped to different HTTP method config.http.prefer405over404 = true; // return 405 instead of 404 if path is mapped to different HTTP method
config.http.defaultContentType = "application/json"; config.http.defaultContentType = "application/json";
config.staticFiles.add(staticFileConfig -> {
staticFileConfig.hostedPath = "/";
staticFileConfig.location = Location.EXTERNAL;
staticFileConfig.directory = "./ui/dist/";
});
}); });
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Shutting down web application"); logger.info("Shutting down web application");
@ -50,15 +45,13 @@ public class WebAPI implements Runnable {
ctx.header("Access-Control-Allow-Origin", "*"); ctx.header("Access-Control-Allow-Origin", "*");
ctx.header("Access-Control-Allow-Methods", "*"); ctx.header("Access-Control-Allow-Methods", "*");
}); });
app.after(ctx -> {
if (!ctx.path().startsWith("/api") && (ctx.status().equals(HttpStatus.NOT_FOUND) || ctx.status().equals(HttpStatus.METHOD_NOT_ALLOWED))) {
ctx.redirect("/index.html");
}
});
app.options("*", ctx -> ctx.status(HttpStatus.OK)); app.options("*", ctx -> ctx.status(HttpStatus.OK));
app.get("/", ctx -> ctx.result("""
{ "message": "Hello World"}
"""));
app.routes(() -> { app.routes(() -> {
path("api", () -> {
path("servers", () -> { path("servers", () -> {
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService)); crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
}); });
@ -66,7 +59,6 @@ public class WebAPI implements Runnable {
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService)); crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
}); });
}); });
});
app.start(this.port); app.start(this.port);
} }

View file

@ -1,6 +1,6 @@
import type { ServerConfig } from "@/models/server"; import type { ServerConfig } from "@/models/server";
const configUrl = "/api/servers/configs/" const configUrl = import.meta.env.VITE_API_URL + "/servers/configs/"
export async function getConfigs(): Promise<ServerConfig[]> { export async function getConfigs(): Promise<ServerConfig[]> {
return fetch(configUrl) return fetch(configUrl)

View file

@ -1,6 +1,6 @@
import type { UserConfig } from '@/models/user' import type { UserConfig } from '@/models/user'
const configUrl = "/api/users/configs/" const configUrl = import.meta.env.VITE_API_URL + "/users/configs/"
export async function getConfigs(): Promise<UserConfig[]> { export async function getConfigs(): Promise<UserConfig[]> {
return fetch(configUrl) return fetch(configUrl)