//! Embedded static assets via rust-embed. use axum::{ http::{header, StatusCode}, response::{IntoResponse, Response}, }; use rust_embed::RustEmbed; #[derive(RustEmbed)] #[folder = "../../ide/"] pub struct Assets; /// Serve `index.html` at the root path. pub async fn serve_index() -> impl IntoResponse { serve_file("index.html") } /// Fallback handler — serves index.html for unknown paths (SPA routing). pub async fn fallback() -> impl IntoResponse { serve_file("index.html") } fn serve_file(path: &str) -> Response { match Assets::get(path) { Some(content) => { let mime = mime_guess::from_path(path) .first_or_octet_stream() .to_string(); ( StatusCode::OK, [(header::CONTENT_TYPE, mime)], content.data.to_vec(), ) .into_response() } None => { // For SPA routing, fall back to index.html match Assets::get("index.html") { Some(content) => ( StatusCode::OK, [(header::CONTENT_TYPE, "text/html; charset=utf-8".to_string())], content.data.to_vec(), ) .into_response(), None => StatusCode::NOT_FOUND.into_response(), } } } }