summaryrefslogtreecommitdiff
path: root/src/ui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.rs')
-rw-r--r--src/ui.rs38
1 files changed, 38 insertions, 0 deletions
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))
+}