#[cfg(feature = "server")]
use rust_embed::RustEmbed;
#[cfg(all(feature = "server", not(docsrs)))]
#[derive(RustEmbed)]
#[folder = "web/out/"]
pub struct WebAssets;
#[cfg(all(feature = "server", docsrs))]
pub struct WebAssets;
#[cfg(all(feature = "server", docsrs))]
impl WebAssets {
pub fn get(_file_path: &str) -> Option<rust_embed::EmbeddedFile> {
None
}
pub fn iter() -> impl Iterator<Item = std::borrow::Cow<'static, str>> {
std::iter::empty()
}
}
#[cfg(feature = "server")]
pub fn get_content_type(path: &str) -> &'static str {
let path = path.to_lowercase();
if path.ends_with(".html") {
"text/html; charset=utf-8"
} else if path.ends_with(".css") {
"text/css; charset=utf-8"
} else if path.ends_with(".js") {
"application/javascript; charset=utf-8"
} else if path.ends_with(".json") {
"application/json; charset=utf-8"
} else if path.ends_with(".png") {
"image/png"
} else if path.ends_with(".jpg") || path.ends_with(".jpeg") {
"image/jpeg"
} else if path.ends_with(".svg") {
"image/svg+xml"
} else if path.ends_with(".ico") {
"image/x-icon"
} else if path.ends_with(".woff") {
"font/woff"
} else if path.ends_with(".woff2") {
"font/woff2"
} else if path.ends_with(".ttf") {
"font/ttf"
} else if path.ends_with(".txt") {
"text/plain; charset=utf-8"
} else {
"application/octet-stream"
}
}
#[cfg(feature = "server")]
pub fn resolve_path(path: &str) -> String {
let path = path.trim_start_matches('/');
if path.is_empty() || path == "/" {
return "index.html".to_string();
}
if !path.contains('.') {
let with_trailing_slash = if path.ends_with('/') {
format!("{}index.html", path)
} else {
format!("{}/index.html", path)
};
if WebAssets::get(&with_trailing_slash).is_some() {
return with_trailing_slash;
}
let with_html = format!("{}.html", path.trim_end_matches('/'));
if WebAssets::get(&with_html).is_some() {
return with_html;
}
}
path.to_string()
}