Skip to main content

rush_sync_server/proxy/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct ProxyConfig {
6    pub enabled: bool,
7    pub port: u16,
8    pub https_port_offset: u16,
9    pub bind_address: String,
10    pub health_check_interval: u64,
11    pub timeout_ms: u64,
12    // Populated from [server] config — avoids re-loading config in proxy context
13    #[serde(default)]
14    pub production_domain: String,
15    #[serde(default)]
16    pub use_lets_encrypt: bool,
17}
18
19impl Default for ProxyConfig {
20    fn default() -> Self {
21        Self {
22            enabled: true,
23            port: 3000,
24            https_port_offset: 443, // HTTPS port = port + offset (e.g. 3443)
25            bind_address: "127.0.0.1".to_string(),
26            health_check_interval: 30,
27            timeout_ms: 5000,
28            production_domain: "localhost".to_string(),
29            use_lets_encrypt: false,
30        }
31    }
32}
33
34// TOML-specific struct for serialization
35#[derive(Debug, Serialize, Deserialize)]
36pub struct ProxyConfigToml {
37    pub enabled: bool,
38    pub port: u16,
39    pub bind_address: String,
40    pub health_check_interval: u64,
41    pub timeout_ms: u64,
42    pub https_port_offset: u16,
43}
44
45impl Default for ProxyConfigToml {
46    fn default() -> Self {
47        Self {
48            enabled: true,
49            port: 3000,
50            https_port_offset: 443,
51            bind_address: "127.0.0.1".to_string(),
52            health_check_interval: 30,
53            timeout_ms: 5000,
54        }
55    }
56}
57
58impl From<ProxyConfig> for ProxyConfigToml {
59    fn from(config: ProxyConfig) -> Self {
60        Self {
61            enabled: config.enabled,
62            port: config.port,
63            https_port_offset: config.https_port_offset,
64            bind_address: config.bind_address,
65            health_check_interval: config.health_check_interval,
66            timeout_ms: config.timeout_ms,
67        }
68    }
69}
70
71impl From<ProxyConfigToml> for ProxyConfig {
72    fn from(config: ProxyConfigToml) -> Self {
73        Self {
74            enabled: config.enabled,
75            port: config.port,
76            https_port_offset: config.https_port_offset,
77            bind_address: config.bind_address,
78            health_check_interval: config.health_check_interval,
79            timeout_ms: config.timeout_ms,
80            // These are populated later from [server] config, not from TOML
81            production_domain: "localhost".to_string(),
82            use_lets_encrypt: false,
83        }
84    }
85}
86
87#[derive(Debug, Clone)]
88pub struct ProxyTarget {
89    pub name: String,
90    pub port: u16,
91    pub healthy: bool,
92    pub last_check: std::time::SystemTime,
93}
94
95#[derive(Debug, Clone)]
96pub struct ProxyRoute {
97    pub subdomain: String,
98    pub target_port: u16,
99    pub server_id: String,
100}
101
102pub type RouteMap = HashMap<String, ProxyRoute>;