summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs3
-rw-r--r--src/lib.rs1
-rw-r--r--src/ui.rs38
3 files changed, 41 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 2d9f512..8b39451 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -10,7 +10,7 @@ use clap::Parser;
use sqlx::sqlite::SqlitePool;
use tokio::net;
-use crate::{app::App, channel, clock, db, event, expire, login, message};
+use crate::{app::App, channel, clock, db, event, expire, login, message, ui};
/// Command-line entry point for running the `hi` server.
///
@@ -110,6 +110,7 @@ fn routers() -> Router<App> {
event::router(),
login::router(),
message::router(),
+ ui::router(),
]
.into_iter()
.fold(Router::default(), Router::merge)
diff --git a/src/lib.rs b/src/lib.rs
index 8ec13da..59cf0f2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,3 +17,4 @@ mod message;
#[cfg(test)]
mod test;
mod token;
+mod ui;
diff --git a/src/ui.rs b/src/ui.rs
new file mode 100644
index 0000000..bba01cc
--- /dev/null
+++ b/src/ui.rs
@@ -0,0 +1,38 @@
+use axum::{
+ extract::Path,
+ http::{header, StatusCode},
+ response::IntoResponse,
+ routing::get,
+ Router,
+};
+
+#[derive(rust_embed::Embed)]
+#[folder = "hi-ui/build"]
+struct Assets;
+
+async fn root() -> impl IntoResponse {
+ asset(Path(String::from("index.html"))).await
+}
+
+async fn asset(Path(path): Path<String>) -> impl IntoResponse {
+ let mime = mime_guess::from_path(&path).first_or_octet_stream();
+
+ match Assets::get(&path) {
+ Some(file) => (
+ StatusCode::OK,
+ [(header::CONTENT_TYPE, mime.as_ref())],
+ file.data,
+ )
+ .into_response(),
+ None => (StatusCode::NOT_FOUND, "").into_response(),
+ }
+}
+
+pub fn router<S>() -> Router<S>
+where
+ S: Clone + Send + Sync + 'static,
+{
+ Router::new()
+ .route("/*path", get(asset))
+ .route("/", get(root))
+}