Skip to main content

kellnr_settings/
origin.rs

1use provcfg::{ClapArgs, Configurable};
2use serde::{Deserialize, Serialize};
3
4use crate::protocol::Protocol;
5
6fn default_hostname() -> String {
7    "127.0.0.1".to_string()
8}
9
10fn default_origin_port() -> u16 {
11    std::env::var("KELLNR_ORIGIN__PORT")
12        .ok()
13        .and_then(|v| v.parse::<u16>().ok())
14        .unwrap_or(8000)
15}
16
17#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone, Configurable, ClapArgs)]
18#[serde(default)]
19#[configurable(clap_prefix = "origin")]
20pub struct Origin {
21    /// External hostname for URLs
22    pub hostname: String,
23
24    /// External port for URLs
25    pub port: u16,
26
27    /// Protocol (http or https), not exposed on the CLI; set via TOML/env
28    #[arg(skip)]
29    pub protocol: Protocol,
30
31    /// URL path prefix
32    pub path: String,
33}
34
35impl Default for Origin {
36    fn default() -> Self {
37        Self {
38            hostname: default_hostname(),
39            port: default_origin_port(),
40            protocol: Protocol::Http,
41            path: String::new(),
42        }
43    }
44}