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) -> 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() -> Router where S: Clone + Send + Sync + 'static, { Router::new() .route("/*path", get(asset)) .route("/", get(root)) }