Using .env config

This commit is contained in:
2025-10-31 15:44:30 +01:00
parent d8b48ed6d8
commit 178adf8bf5
2 changed files with 13 additions and 1 deletions
+5 -1
View File
@@ -4,7 +4,11 @@ use voxa_server::{ServerConfig, utils::vfs};
fn main() -> voxa_server::Result<()> { fn main() -> voxa_server::Result<()> {
let root = PathBuf::from(""); let root = PathBuf::from("");
let config: ServerConfig = vfs::read_config(&root.join("config.json"))?; let config: ServerConfig = if let Ok(env_config) = en::var("VX_CONFIG") {
ServerConfig::from_str(&env_config)?
} else {
vfs::read_config(&root.join("config.json"))?
};
config.build(&root).run()?; config.build(&root).run()?;
Ok(()) Ok(())
} }
+8
View File
@@ -2,6 +2,7 @@ use std::{
collections::HashSet, collections::HashSet,
net::{TcpListener, TcpStream}, net::{TcpListener, TcpStream},
path::{Path, PathBuf}, path::{Path, PathBuf},
str::FromStr,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@@ -206,3 +207,10 @@ impl Server {
res res
} }
} }
impl FromStr for ServerConfig {
type Err = serde_json::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
serde_json::from_str(s)
}
}