From 7ed85f30dccbb2907d58b52469c4a0572e9ab912 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Fri, 31 Oct 2025 15:45:20 +0100 Subject: [PATCH] Using .env config --- cli/src/main.rs | 2 +- src/lib.rs | 12 ++++-------- test-plugin/src/main.rs | 6 +++++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index b17d399..1e5c9a7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -4,7 +4,7 @@ use voxa_server::{ServerConfig, utils::vfs}; fn main() -> voxa_server::Result<()> { let root = PathBuf::from(""); - let config: ServerConfig = if let Ok(env_config) = en::var("VX_CONFIG") { + let config: ServerConfig = if let Ok(env_config) = std::env::var("VX_CONFIG") { ServerConfig::from_str(&env_config)? } else { vfs::read_config(&root.join("config.json"))? diff --git a/src/lib.rs b/src/lib.rs index 9a80333..ea0cb2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ use std::{ collections::HashSet, net::{TcpListener, TcpStream}, path::{Path, PathBuf}, - str::FromStr, sync::{Arc, Mutex}, }; @@ -52,6 +51,10 @@ impl ServerConfig { pub fn build(self, root: &Path) -> Arc { Server::new_config(root, self) } + + pub fn from_str(s: &str) -> std::result::Result { + serde_json::from_str(s) + } } impl Server { @@ -207,10 +210,3 @@ 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) - } -} diff --git a/test-plugin/src/main.rs b/test-plugin/src/main.rs index c0a9e5e..7400176 100644 --- a/test-plugin/src/main.rs +++ b/test-plugin/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) = std::env::var("VX_CONFIG") { + ServerConfig::from_str(&env_config)? + } else { + vfs::read_config(&root.join("config.json"))? + }; let server = config.build(&root); server.add_plugin(Box::new(test_plugin::MyPlugin::default())); server.run()?;