From 178adf8bf5aced8299b2153edbc911e11c9e1237 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Fri, 31 Oct 2025 15:41:47 +0100 Subject: [PATCH] Using .env config --- cli/src/main.rs | 6 +++++- src/lib.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index a5c5dc3..b17d399 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -4,7 +4,11 @@ use voxa_server::{ServerConfig, utils::vfs}; fn main() -> voxa_server::Result<()> { 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()?; Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 02a81ff..9a80333 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ use std::{ collections::HashSet, net::{TcpListener, TcpStream}, path::{Path, PathBuf}, + str::FromStr, sync::{Arc, Mutex}, }; @@ -206,3 +207,10 @@ impl Server { res } } + +impl FromStr for ServerConfig { + type Err = serde_json::Error; + fn from_str(s: &str) -> std::result::Result { + serde_json::from_str(s) + } +}