use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use rust_embed::Embed;
#[derive(Embed)]
#[folder = "ui/dist/"]
struct Assets;
pub(super) async fn static_files(uri: axum::http::Uri) -> Response {
let path = uri.path().trim_start_matches('/');
if !path.is_empty() {
if let Some(content) = Assets::get(path) {
let mime = mime_guess::from_path(path).first_or_octet_stream();
return (
[(axum::http::header::CONTENT_TYPE, mime.as_ref())],
content.data,
)
.into_response();
}
}
match Assets::get("index.html") {
Some(content) => (
[(axum::http::header::CONTENT_TYPE, "text/html; charset=utf-8")],
content.data,
)
.into_response(),
None => (
StatusCode::NOT_FOUND,
"Cory was built without UI (no NPM at build time)",
)
.into_response(),
}
}