first commit

This commit is contained in:
2025-06-27 21:43:54 +02:00
commit 6ef4576cb2
33 changed files with 2185 additions and 0 deletions

12
web/build.gradle.kts Normal file
View File

@@ -0,0 +1,12 @@
description = "Umbrella : Web"
dependencies{
implementation("de.srsoftware:tools.http:6.0.0")
}
tasks.processResources {
System.out.println("Copying from dist…")
from("../frontend/dist") {
into("web")
}
}

View File

@@ -0,0 +1,36 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.web;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.WARNING;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.tools.Path;
import de.srsoftware.tools.PathHandler;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class WebHandler extends PathHandler {
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
LOG.log(DEBUG,"doGet({0},ex)",path);
if (path.empty()) {
path.push("index.html");
}
var url = getClass().getClassLoader().getResource("web/"+path);
if (url == null) return sendContent(ex,404,path+" not found!");
LOG.log(DEBUG,"Trying to load {0}",url);
var bos = new ByteArrayOutputStream();
var conn = url.openConnection();
var mime = conn.getContentType();
try (var stream = conn.getInputStream()){
stream.transferTo(bos);
ex.getResponseHeaders().add(CONTENT_TYPE,mime);
return sendContent(ex,bos.toByteArray());
} catch (Exception e) {
LOG.log(WARNING,"Failed to load {0}",url);
return false;
}
}
}