diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 18:17:25 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 18:17:25 -0400 |
| commit | 0c0cd1daa0c6640e81bb6282ae4a1c574cf135f4 (patch) | |
| tree | d6b4195cc7be249fb55cb1160f01db0a6daa84f1 /src/ui.rs | |
| parent | 54a542df2164e421e78b48d7229a6bfabbc5c26b (diff) | |
| parent | 40cc35bcc9b881a61ca62c67e107bb17c2748f57 (diff) | |
Merge branch 'wip/ui'
Diffstat (limited to 'src/ui.rs')
| -rw-r--r-- | src/ui.rs | 38 |
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)) +} |
