76 lines
1.9 KiB
Rust
76 lines
1.9 KiB
Rust
use serde::Deserialize;
|
|
use std::path::PathBuf;
|
|
use std::fs;
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct TlsConfig {
|
|
pub enabled: bool,
|
|
pub cert_path: PathBuf,
|
|
pub key_path: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct MaskingConfig {
|
|
pub enabled: bool,
|
|
pub headers: Vec<String>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct RouteConfig {
|
|
pub path: String,
|
|
pub response_file: PathBuf,
|
|
pub status_code: u16,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct Config {
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub routes: Vec<RouteConfig>,
|
|
pub masking: MaskingConfig,
|
|
pub tls: TlsConfig,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn load() -> Self {
|
|
match fs::read_to_string("config.json") {
|
|
Ok(content) => {
|
|
serde_json::from_str(&content).unwrap_or_else(|e| {
|
|
eprintln!("Warning: Failed to parse config.json ({}), using defaults.", e);
|
|
Self::default()
|
|
})
|
|
}
|
|
Err(_) => {
|
|
Self::default()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
host: "127.0.0.1".to_string(),
|
|
port: 3000,
|
|
routes: vec![RouteConfig {
|
|
path: "/".to_string(),
|
|
response_file: PathBuf::from("response.json"),
|
|
status_code: 200,
|
|
}],
|
|
masking: MaskingConfig {
|
|
enabled: true,
|
|
headers: vec![
|
|
"authorization".to_string(),
|
|
"x-api-key".to_string(),
|
|
"cookie".to_string(),
|
|
],
|
|
},
|
|
tls: TlsConfig {
|
|
enabled: false,
|
|
cert_path: PathBuf::from("cert.pem"),
|
|
key_path: PathBuf::from("key.pem"),
|
|
},
|
|
}
|
|
}
|
|
}
|