add dir option to FileServer

This commit is contained in:
Daniella / Tove 2022-07-07 13:59:09 +02:00
parent 8eca83854d
commit 5775f625c9
2 changed files with 6 additions and 9 deletions

View file

@ -4,17 +4,14 @@ import java.net.Socket;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import de.tudbut.async.Callback;
import de.tudbut.async.ComposeCallback;
import de.tudbut.async.TaskCallable;
import de.tudbut.tryumph.config.IRequestCatcher;
import de.tudbut.tryumph.events.GET;
import de.tudbut.tryumph.events.POST;
import de.tudbut.tryumph.events.Path;
import de.tudbut.tryumph.events.RequestHandler;
import de.tudbut.tryumph.server.HTMLParsing;
import de.tudbut.tryumph.server.Request;
import de.tudbut.tryumph.server.Response;
import tudbut.parsing.TCN;
@ -62,12 +59,12 @@ public class FileServer implements IRequestCatcher, RequestHandler.Listener {
@GET
@Path("/.*")
public void onIndex(Request request, Callback<Response> res, Callback<Throwable> rej) {
res.call(new Response(request, request.context.file("." + request.path.replace("..", "")), 200, "OK"));
res.call(new Response(request, request.context.file(data.getString("dir") + request.path.replace("..", "")), 200, "OK"));
}
@Override
public void handleError(Request request, Throwable error, Callback<Response> res, Callback<Throwable> rej) {
@Override
public void handleError(Request request, Throwable error, Callback<Response> res, Callback<Throwable> rej) {
rej.call(error);
}
}
}

View file

@ -24,13 +24,13 @@ public class BrowserContext {
public final UUID uuid = UUID.randomUUID();
public TCN data;
private final IRequestCatcher requestCatcher;
private final IRequestCatcher requestCatcher;
public boolean useJavaScript = false;
private boolean needsChange = false;
private BrowserContext(IRequestCatcher requestCatcher) {
this.requestCatcher = requestCatcher;
data = new TCN("json");
data = new TCN("json");
}
private BrowserContext(String cookie, IRequestCatcher requestCatcher) {