Allow the http server to serve static files (such as downloadable resources)

This commit is contained in:
Melledy
2025-11-19 03:02:24 -08:00
parent 06f854be55
commit 207a1e25d4
3 changed files with 9 additions and 1 deletions

1
.gitignore vendored
View File

@@ -63,6 +63,7 @@ tmp/
/plugins /plugins
/proto /proto
/resources /resources
/web
# Compiled # Compiled
/*.jar /*.jar

View File

@@ -24,6 +24,7 @@ public class Config {
public int customDataVersion = 0; public int customDataVersion = 0;
public String resourceDir = "./resources"; public String resourceDir = "./resources";
public String webFilesDir = "./web";
public String patchListPath = "./patchlist.json"; public String patchListPath = "./patchlist.json";
@Getter @Getter

View File

@@ -19,6 +19,7 @@ import emu.nebula.util.JsonUtils;
import io.javalin.Javalin; import io.javalin.Javalin;
import io.javalin.http.ContentType; import io.javalin.http.ContentType;
import io.javalin.http.Context; import io.javalin.http.Context;
import io.javalin.http.staticfiles.Location;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
@@ -32,8 +33,13 @@ public class HttpServer {
private byte[] diff; private byte[] diff;
public HttpServer(ServerType type) { public HttpServer(ServerType type) {
this.app = Javalin.create();
this.type = type; this.type = type;
this.app = Javalin.create(javalinConfig -> {
var staticFilesDir = new File(Nebula.getConfig().getWebFilesDir());
if (staticFilesDir.exists()) {
javalinConfig.staticFiles.add(staticFilesDir.getPath(), Location.EXTERNAL);
}
});
this.loadPatchList(); this.loadPatchList();
this.addRoutes(); this.addRoutes();