Compare commits

..

6 commits

Author SHA1 Message Date
1060d4d577 Update Javalin to version 5.5.0 2023-05-05 01:25:15 +02:00
24adb8d0ce Add redirect to index.html if file was not found
This should help using the SPA
2023-05-05 01:23:24 +02:00
ceb2fe27a7 Add /api to api endpoints
To differentiate beween file access and api call.
2023-05-05 01:22:27 +02:00
bc4a5240d7 Fix reading API_PORT env 2023-05-05 01:21:07 +02:00
9b6409914a Add vuejs to build container image 2023-05-05 01:20:24 +02:00
391f3969c6 Add static fileserver for vue app 2023-05-05 00:18:41 +02:00
7 changed files with 44 additions and 16 deletions

View file

@ -1,3 +1,13 @@
*
!src/
!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 the application
# Stage 1: Build java application
FROM docker.io/maven:3.9-eclipse-temurin-19 AS maven
WORKDIR /app
COPY pom.xml .
@ -7,9 +7,19 @@ RUN mvn package
COPY src/ /app/src/
RUN mvn package
# Stage 2: Create the jlink app
# Stage 2: Build vuejs application
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
WORKDIR /app
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"]

View file

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

View file

@ -39,7 +39,7 @@ public class Main {
System.exit(1);
}
String apiPortStr = System.getenv("PAI_PORT") != null ? System.getenv("API_PORT") : "8080";
String apiPortStr = System.getenv("API_PORT") != null ? System.getenv("API_PORT") : "8080";
int apiPort = Integer.parseInt(apiPortStr);
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.user.ConfigUserCrudHandler;
import io.javalin.Javalin;
import io.javalin.http.HandlerType;
import io.javalin.http.HttpStatus;
import io.javalin.http.staticfiles.Location;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,6 +32,11 @@ public class WebAPI implements Runnable {
config.plugins.enableDevLogging();
config.http.prefer405over404 = true; // return 405 instead of 404 if path is mapped to different HTTP method
config.http.defaultContentType = "application/json";
config.staticFiles.add(staticFileConfig -> {
staticFileConfig.hostedPath = "/";
staticFileConfig.location = Location.EXTERNAL;
staticFileConfig.directory = "./ui/dist/";
});
});
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Shutting down web application");
@ -45,18 +50,21 @@ public class WebAPI implements Runnable {
ctx.header("Access-Control-Allow-Origin", "*");
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.get("/", ctx -> ctx.result("""
{ "message": "Hello World"}
"""));
app.routes(() -> {
path("servers", () -> {
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
});
path("users", () -> {
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
path("api", () -> {
path("servers", () -> {
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
});
path("users", () -> {
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
});
});
});

View file

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

View file

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