Skip to content

Commit

Permalink
Server: Welcome to Athena!
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Sep 22, 2023
1 parent 24fd6b3 commit b67e3a6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static class AthenaSoraAdapter extends SoraPlugin {

@Override
public void onInit(Sora sora) {
sora.addProvider(this, new UIRoutes());
}

@Override
Expand Down
49 changes: 49 additions & 0 deletions server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.e3ndr.athena.webui;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import co.casterlabs.rakurai.io.http.StandardHttpStatus;
import co.casterlabs.rakurai.io.http.server.HttpResponse;
import co.casterlabs.sora.api.http.HttpProvider;
import co.casterlabs.sora.api.http.SoraHttpSession;
import co.casterlabs.sora.api.http.annotations.HttpEndpoint;

class UIRoutes implements HttpProvider {

@HttpEndpoint(uri = "/*")
public HttpResponse redirectToUI(SoraHttpSession session) {
return html(
"<h1>Welcome to Athena!</h1>",
);
}

private static HttpResponse html(String... body) {
List<String> lines = new LinkedList<>();
lines.addAll(
Arrays.asList(
"<!DOCTYPE html>",
"<html>",
" <head>",
" <meta charset=\"utf-8\" />",
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />",
" <title>Athena</title>",
" </head>",
" <body>"
)
);
lines.addAll(Arrays.asList(body));
lines.addAll(
Arrays.asList(
" </body>",
"</html>"
)
);
return HttpResponse
.newFixedLengthResponse(StandardHttpStatus.OK, String.join("\r\n", lines))
.setMimeType("text/html");
}

}

0 comments on commit b67e3a6

Please sign in to comment.