slave 0.4.0

Laravel-inspired CLI for Rust MCP servers: scaffold apps whose business operations are MCP tools over Streamable HTTP, with built-in auth, users, roles and Turso migrations
use slave_framework::{database, env};

/// Used when `APP_NAME` is not set.
const DEFAULT_NAME: &str = "{{ name }}";

/// Application settings, read from the environment (and `.env`, if present).
#[derive(Debug, Clone)]
pub struct Config {
    pub name: String,
    pub host: String,
    pub port: u16,
    pub database_path: String,
    /// Lifetime of bearer tokens issued at login, in days.
    pub token_ttl_days: u32,
    /// `Host` header values the MCP endpoint accepts (DNS rebinding protection).
    pub mcp_allowed_hosts: Vec<String>,
}

impl Config {
    pub fn from_env() -> slave_framework::Result<Self> {
        Ok(Self {
            name: env::var_or("APP_NAME", DEFAULT_NAME),
            host: env::var_or("APP_HOST", "127.0.0.1"),
            port: env::parse_or("APP_PORT", 3000)?,
            database_path: database::path_from_env(),
            token_ttl_days: env::parse_or("AUTH_TOKEN_TTL_DAYS", 30)?,
            mcp_allowed_hosts: env::var_or("MCP_ALLOWED_HOSTS", "localhost,127.0.0.1,::1")
                .split(',')
                .map(str::trim)
                .filter(|host| !host.is_empty())
                .map(str::to_owned)
                .collect(),
        })
    }
}