pub mod helpers;
mod routes;
mod server;
mod static_files;
pub use server::serve;
use std::sync::OnceLock;
static BASE_PATH: OnceLock<String> = OnceLock::new();
pub(crate) fn bp() -> &'static str {
BASE_PATH.get().map(|s| s.as_str()).unwrap_or("")
}
pub(crate) fn normalize_base_path(path: Option<&str>) -> crate::Result<String> {
match path {
None => Ok(String::new()),
Some(p) => {
let trimmed = p.trim().trim_matches('/');
if trimmed.is_empty() {
Ok(String::new())
} else if !trimmed
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
{
Err(miette::miette!(
"PITCHFORK_WEB_PATH must contain only alphanumeric characters, hyphens, or underscores, got: {trimmed:?}"
))
} else {
Ok(format!("/{trimmed}"))
}
}
}
}