refactor: enhance asset retrieval logic to support fallback for client subfolder

This commit is contained in:
GW_MC
2026-05-31 02:36:42 +00:00
parent 9f72cd4bbb
commit cb4ad27e89

View File

@@ -37,7 +37,11 @@ pub async fn get_fallback_handler() -> Result<axum::response::Html<Vec<u8>>, axu
} }
fn get_index_html() -> Option<Vec<u8>> { fn get_index_html() -> Option<Vec<u8>> {
FrontendAssets::get(INDEX_HTML).map(|asset| asset.data.as_ref().to_owned()) // Try root index.html first, then fall back to client/index.html when assets
// are packaged under the `client/` subfolder.
FrontendAssets::get(INDEX_HTML)
.or_else(|| FrontendAssets::get(&format!("client/{}", INDEX_HTML)))
.map(|asset| asset.data.as_ref().to_owned())
} }
async fn get_file_handler( async fn get_file_handler(
@@ -49,7 +53,10 @@ async fn get_file_handler(
path path
}; };
match FrontendAssets::get(&file_path) { // Try direct lookup first, then fallback to the `client/` subfolder.
match FrontendAssets::get(&file_path)
.or_else(|| FrontendAssets::get(&format!("client/{}", file_path)))
{
Some(asset) => { Some(asset) => {
let content_type = mime_guess::from_path(&file_path).first_or_octet_stream(); let content_type = mime_guess::from_path(&file_path).first_or_octet_stream();
let response = axum::response::Response::builder() let response = axum::response::Response::builder()