use poem::http::StatusCode; use poem::{Endpoint, Request, Response, Result}; use rust_embed::Embed; #[derive(Embed)] #[folder = "../landing/build"] struct Assets; pub struct StaticAssets; impl StaticAssets { pub fn new() -> Self { Self } } impl Endpoint for StaticAssets { type Output = Response; async fn call(&self, req: Request) -> Result { let path = req.uri().path().trim_start_matches('/'); if let Some(file) = Assets::get(path) { let mime = mime_guess::from_path(path) .first_or_octet_stream() .to_string(); Ok(Response::builder() .header("Content-Type", &mime) .header("Cache-Control", "public, max-age=31536000, immutable") .body(file.data.into_owned())) } else if let Some(file) = Assets::get("index.html") { Ok(Response::builder() .header("Content-Type", "text/html") .body(file.data.into_owned())) } else { Ok(Response::builder() .status(StatusCode::NOT_FOUND) .body(Vec::new())) } } }