first commit
This commit is contained in:
12
web/build.gradle.kts
Normal file
12
web/build.gradle.kts
Normal 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")
|
||||
}
|
||||
}
|
||||
36
web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java
Normal file
36
web/src/main/java/de/srsoftware/umbrella/web/WebHandler.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user