kellnr_settings/
origin.rs

1use serde::{Deserialize, Serialize};
2
3use crate::protocol::Protocol;
4
5#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)]
6#[serde(default)]
7pub struct Origin {
8    pub hostname: String,
9    pub port: u16,
10    pub protocol: Protocol,
11    pub path: String,
12}
13
14impl Default for Origin {
15    fn default() -> Self {
16        // For local development the origin defaults to 127.0.0.1:8000.
17        //
18        // For integration tests (e.g. Docker Desktop on macOS) the host port is often
19        // dynamically mapped. When Kellnr generates crates.io download URLs, it uses
20        // `origin.hostname` + `origin.port`, so we must be able to override the port
21        // at runtime.
22        //
23        // We support this via env var `KELLNR_ORIGIN__PORT` which mirrors how other
24        // settings are configured.
25        let port = std::env::var("KELLNR_ORIGIN__PORT")
26            .ok()
27            .and_then(|v| v.parse::<u16>().ok())
28            .unwrap_or(8000);
29
30        Self {
31            hostname: "127.0.0.1".to_string(),
32            port,
33            protocol: Protocol::Http,
34            path: String::new(),
35        }
36    }
37}