#[derive(Debug, Clone)]
pub struct InertiaConfig {
pub app_name: String,
pub vite_dev_server: String,
pub entry_point: String,
pub version: String,
pub development: bool,
pub html_template: Option<String>,
pub manifest_path: String,
}
impl Default for InertiaConfig {
fn default() -> Self {
let vite_dev_server = std::env::var("VITE_DEV_SERVER")
.unwrap_or_else(|_| "http://localhost:5173".to_string());
let is_dev = !matches!(
std::env::var("APP_ENV").ok().as_deref(),
Some("production") | Some("staging")
);
let app_name = std::env::var("APP_NAME").unwrap_or_else(|_| "Ferro".to_string());
Self {
app_name,
vite_dev_server,
entry_point: "src/main.tsx".to_string(),
version: "1.0".to_string(),
development: is_dev,
html_template: None,
manifest_path: "public/.vite/manifest.json".to_string(),
}
}
}
impl InertiaConfig {
pub fn new() -> Self {
Self::default()
}
pub fn vite_dev_server(mut self, url: impl Into<String>) -> Self {
self.vite_dev_server = url.into();
self
}
pub fn entry_point(mut self, entry: impl Into<String>) -> Self {
self.entry_point = entry.into();
self
}
pub fn version(mut self, version: impl Into<String>) -> Self {
self.version = version.into();
self
}
pub fn production(mut self) -> Self {
self.development = false;
self
}
pub fn development(mut self) -> Self {
self.development = true;
self
}
pub fn app_name(mut self, name: impl Into<String>) -> Self {
self.app_name = name.into();
self
}
pub fn manifest_path(mut self, path: impl Into<String>) -> Self {
self.manifest_path = path.into();
self
}
pub fn html_template(mut self, template: impl Into<String>) -> Self {
self.html_template = Some(template.into());
self
}
}