use axum::http::{StatusCode, Uri, header};
use axum::response::{Html, IntoResponse, Response};
use rust_embed::Embed;
#[derive(Embed)]
#[folder = "web/build"]
struct Assets;
pub async fn serve(uri: Uri) -> Response {
let path = uri.path().trim_start_matches('/');
if let Some(file) = Assets::get(path) {
let mime = mime_guess::from_path(path).first_or_octet_stream();
(
StatusCode::OK,
[(header::CONTENT_TYPE, mime.as_ref())],
file.data,
)
.into_response()
} else {
match Assets::get("index.html") {
Some(file) => Html(file.data).into_response(),
None => (StatusCode::NOT_FOUND, "Frontend not built").into_response(),
}
}
}