1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Deserialize, Serialize)]
6#[serde(default)]
7pub struct HttpConfig {
8 pub http_address: String,
9 pub https_address: Option<String>,
10 pub https_cert_path: Option<PathBuf>,
11 pub https_private_key_path: Option<PathBuf>,
12 pub enable_doc: bool,
13 pub proxy: ProxyConfig,
14 pub cors: CorsConfig,
15 pub self_signed_cert: SelfSignedCertConfig,
17}
18
19#[derive(Debug, Clone, Deserialize, Serialize)]
20#[serde(default)]
21pub struct ProxyConfig {
22 pub trusted_proxies: Vec<String>,
24 pub trust_x_forwarded_for: bool,
26 pub trust_x_real_ip: bool,
28}
29
30#[derive(Debug, Clone, Deserialize, Serialize)]
31#[serde(default)]
32pub struct SelfSignedCertConfig {
33 pub enabled: bool,
36 pub common_name: String,
38 pub san: Vec<String>,
40 pub validity_days: u32,
42 pub renew_before_days: u32,
44 pub check_interval_secs: u64,
46}
47
48impl Default for SelfSignedCertConfig {
49 fn default() -> Self {
50 Self {
51 enabled: false,
52 common_name: "localhost".to_string(),
53 san: vec!["127.0.0.1".to_string(), "::1".to_string()],
54 validity_days: 365,
55 renew_before_days: 30,
56 check_interval_secs: 3600, }
58 }
59}
60
61#[derive(Debug, Clone, Deserialize, Serialize)]
62#[serde(default)]
63pub struct CorsConfig {
64 pub enabled: bool,
66 pub allow_any_origin: bool,
71 pub allowed_origins: Vec<String>,
74 pub allow_credentials: bool,
77}
78
79impl Default for HttpConfig {
80 fn default() -> Self {
81 Self {
82 http_address: "0.0.0.0:3000".to_string(),
83 https_address: Default::default(),
84 https_cert_path: Default::default(),
85 https_private_key_path: Default::default(),
86 enable_doc: Default::default(),
87 proxy: ProxyConfig::default(),
88 cors: CorsConfig::default(),
89 self_signed_cert: SelfSignedCertConfig::default(),
90 }
91 }
92}
93
94impl Default for ProxyConfig {
95 fn default() -> Self {
96 Self {
97 trusted_proxies: Vec::new(),
98 trust_x_forwarded_for: true,
99 trust_x_real_ip: true,
100 }
101 }
102}
103
104impl Default for CorsConfig {
105 fn default() -> Self {
106 Self {
107 enabled: true,
108 allow_any_origin: true,
109 allowed_origins: vec![],
110 allow_credentials: false,
111 }
112 }
113}