mirror of
https://github.com/Xevion/banner.git
synced 2025-12-18 00:11:16 -06:00
fix: simplify asset serving, use fallback primarily
This commit is contained in:
@@ -9,6 +9,7 @@ use axum::{
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use rust_embed::RustEmbed;
|
||||
use tracing::debug;
|
||||
|
||||
/// Embedded web assets from the dist directory
|
||||
#[derive(RustEmbed)]
|
||||
@@ -17,36 +18,6 @@ use rust_embed::RustEmbed;
|
||||
#[exclude = "*.map"]
|
||||
pub struct WebAssets;
|
||||
|
||||
/// Serve embedded static assets
|
||||
pub async fn serve_asset(Path(path): Path<String>) -> Response {
|
||||
let path = path.trim_start_matches('/');
|
||||
|
||||
match WebAssets::get(path) {
|
||||
Some(content) => {
|
||||
let mime_type = mime_guess::from_path(path).first_or_text_plain();
|
||||
let data = content.data.to_vec();
|
||||
([(header::CONTENT_TYPE, mime_type.as_ref())], data).into_response()
|
||||
}
|
||||
None => (StatusCode::NOT_FOUND, "Asset not found").into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Serve the main SPA index.html for client-side routing
|
||||
pub async fn serve_spa_index() -> Response {
|
||||
match WebAssets::get("index.html") {
|
||||
Some(content) => {
|
||||
let data = content.data.to_vec();
|
||||
let html_content = String::from_utf8_lossy(&data).to_string();
|
||||
Html(html_content).into_response()
|
||||
}
|
||||
None => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Failed to load index.html",
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
const ASSET_EXTENSIONS: &[&str] = &[
|
||||
"js", "css", "png", "jpg", "jpeg", "gif", "svg", "ico", "woff", "woff2", "ttf", "eot",
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user