Using .env config
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ 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 = 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)?
|
ServerConfig::from_str(&env_config)?
|
||||||
} else {
|
} else {
|
||||||
vfs::read_config(&root.join("config.json"))?
|
vfs::read_config(&root.join("config.json"))?
|
||||||
|
|||||||
+4
-8
@@ -2,7 +2,6 @@ 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},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,6 +51,10 @@ impl ServerConfig {
|
|||||||
pub fn build(self, root: &Path) -> Arc<Server> {
|
pub fn build(self, root: &Path) -> Arc<Server> {
|
||||||
Server::new_config(root, self)
|
Server::new_config(root, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_str(s: &str) -> std::result::Result<Self, serde_json::Error> {
|
||||||
|
serde_json::from_str(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
@@ -207,10 +210,3 @@ 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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) = std::env::var("VX_CONFIG") {
|
||||||
|
ServerConfig::from_str(&env_config)?
|
||||||
|
} else {
|
||||||
|
vfs::read_config(&root.join("config.json"))?
|
||||||
|
};
|
||||||
let server = config.build(&root);
|
let server = config.build(&root);
|
||||||
server.add_plugin(Box::new(test_plugin::MyPlugin::default()));
|
server.add_plugin(Box::new(test_plugin::MyPlugin::default()));
|
||||||
server.run()?;
|
server.run()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user