find head relative to asset root

This commit is contained in:
Evan Almloff committed 2023-08-18 10:57:30 -05:00
1 parent 1cbf549847
commit 7b2bf4acc5
2 files changed
+10 -5

No files matched your search

+6 -3
View File
@@ -114,9 +114,7 @@ pub(super) fn desktop_handler(
let path = PathBuf::from(&*decoded);
// If the path is relative, we'll try to serve it from the assets directory.
let mut asset = get_asset_root()
.unwrap_or_else(|| Path::new(".").to_path_buf())
.join(&path);
let mut asset = get_asset_root_or_default().join(&path);
if !asset.exists() {
asset = PathBuf::from("/").join(path);
@@ -135,6 +133,11 @@ pub(super) fn desktop_handler(
.map_err(From::from)
}
#[allow(unreachable_code)]
pub(crate) fn get_asset_root_or_default() -> PathBuf {
get_asset_root().unwrap_or_else(|| Path::new(".").to_path_buf())
}
#[allow(unreachable_code)]
fn get_asset_root() -> Option<PathBuf> {
/*
+4 -2
View File
@@ -25,10 +25,12 @@ pub fn build(
}
#[cfg(not(debug_assertions))]
{
match std::fs::read_to_string("./dist/__assets_head.html") {
let head = crate::protocol::get_asset_root_or_default();
let head = head.join("dist/__assets_head.html");
match std::fs::read_to_string(&head) {
Ok(s) => Some(s),
Err(err) => {
log::error!("Failed to read ./dist/__assets_head.html: {}", err);
log::error!("Failed to read {head:?}: {err}");
None
}
}