2021-10-21 08:43:59 +00:00
|
|
|
mod config;
|
2021-10-26 15:02:05 +00:00
|
|
|
mod plugins;
|
2021-10-21 08:43:59 +00:00
|
|
|
mod servers;
|
2023-10-04 22:23:34 +00:00
|
|
|
mod upstreams;
|
2021-10-21 08:43:59 +00:00
|
|
|
|
2023-10-05 11:32:24 +00:00
|
|
|
use crate::config::ConfigV1;
|
2021-10-21 08:43:59 +00:00
|
|
|
use crate::servers::Server;
|
|
|
|
|
|
|
|
use log::{debug, error};
|
2021-12-30 14:05:25 +00:00
|
|
|
use std::env;
|
2023-08-25 20:53:46 +00:00
|
|
|
use std::path::Path;
|
2021-10-21 08:43:59 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-08-25 20:53:46 +00:00
|
|
|
let config_path = find_config();
|
2021-11-01 08:06:47 +00:00
|
|
|
|
2023-10-05 11:32:24 +00:00
|
|
|
let config = match ConfigV1::new(&config_path) {
|
2021-10-21 08:43:59 +00:00
|
|
|
Ok(config) => config,
|
|
|
|
Err(e) => {
|
|
|
|
println!("Could not load config: {:?}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
debug!("{:?}", config);
|
|
|
|
|
2023-10-05 11:32:24 +00:00
|
|
|
let mut server = Server::new_from_v1_config(config.base);
|
2021-10-21 08:43:59 +00:00
|
|
|
debug!("{:?}", server);
|
|
|
|
|
2021-12-30 14:05:25 +00:00
|
|
|
let _ = server.run();
|
|
|
|
error!("Server ended with errors");
|
2021-10-21 08:43:59 +00:00
|
|
|
}
|
2023-08-25 20:53:46 +00:00
|
|
|
|
|
|
|
fn find_config() -> String {
|
|
|
|
let config_path =
|
|
|
|
env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string());
|
|
|
|
|
|
|
|
if Path::new(&config_path).exists() {
|
|
|
|
return config_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
if Path::new("config.yaml").exists() {
|
|
|
|
return String::from("config.yaml");
|
|
|
|
}
|
|
|
|
|
|
|
|
String::from("")
|
|
|
|
}
|