Compare commits
6 commits
abbb02729a
...
1060d4d577
Author | SHA1 | Date | |
---|---|---|---|
1060d4d577 | |||
24adb8d0ce | |||
ceb2fe27a7 | |||
bc4a5240d7 | |||
9b6409914a | |||
391f3969c6 |
7 changed files with 44 additions and 16 deletions
|
@ -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/
|
14
Dockerfile
14
Dockerfile
|
@ -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"]
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,13 +50,15 @@ 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("api", () -> {
|
||||
path("servers", () -> {
|
||||
crud("configs/{id}", new ConfigCrudHandler(this.serverDBService));
|
||||
});
|
||||
|
@ -59,6 +66,7 @@ public class WebAPI implements Runnable {
|
|||
crud("configs/{id}", new ConfigUserCrudHandler(this.userDBService));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.start(this.port);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue