use axum::{
http::{header, StatusCode, Uri},
response::{Html, IntoResponse, Response},
};
use c2a_devtools_frontend::Assets;
static INDEX_HTML: &str = "index.html";
pub async fn serve(uri: Uri) -> Response {
let path = uri.path().trim_start_matches('/');
if path.is_empty() || path == INDEX_HTML {
return index_html().await;
}
match Assets::get(path) {
Some(content) => {
let mime = mime_guess::from_path(path).first_or_octet_stream();
([(header::CONTENT_TYPE, mime.as_ref())], content.data).into_response()
}
None => index_html().await,
}
}
async fn index_html() -> Response {
match Assets::get(INDEX_HTML) {
Some(content) => Html(content.data).into_response(),
None => not_found().await,
}
}
async fn not_found() -> Response {
(StatusCode::NOT_FOUND, "404").into_response()
}