From 61679da20bc5f8b5e27e80a0f2846b000f1b6f4b Mon Sep 17 00:00:00 2001 From: Leo dev Date: Thu, 30 Oct 2025 12:45:22 +0100 Subject: [PATCH] Using .env config --- .gitignore | 1 + README.md | 26 ++++++++++++++++++++++++++ src/main.rs | 10 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 191779a..9e4c1f8 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ target /target +.env *.db config.json \ No newline at end of file diff --git a/README.md b/README.md index c1c35dc..318c5f7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,32 @@ The server for the DM and notification system of Voxa +## Setup + +### Using `config.json` (Usually when you self host) + +`cargo run` + +### Using `.env` + +```python +#.env +VX_CONFIG='{"server_name":"Server Name","server_id":"","server_key":"","port":7090,"channels":[]}' +``` + +If your env is automatically loaded + +```bash +cargo run +``` + +Run this if you are running on self host or when the .env isn't automatically loaded + +```bash +set -a; source .env; set +a +cargo run +``` + ### What is a Voxa Node? A voxa node is a server that handles DMs sent to you and push message notifications, a client will keep a constant connection with their chosen node and when a sender wants to send a DM or a message notification they can make a HTTP request to the same port, it's important to note that a node server only handles the receiving side, unless both parties are in the same node. diff --git a/src/main.rs b/src/main.rs index 3867824..c263a37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod server; mod types; mod utils; +use std::env; use std::path::PathBuf; pub use anyhow::Context as ErrorContext; @@ -16,7 +17,14 @@ use crate::utils::vfs; fn main() -> Result<()> { let root = PathBuf::from(""); - let config: ServerConfig = vfs::read_config(&root.join("config.json"))?; + + let config: ServerConfig = if let Ok(env_config) = env::var("VX_CONFIG") { + serde_json::from_str(&env_config)? + } else { + vfs::read_config(&root.join("config.json"))? + }; + config.build(&root).run()?; + Ok(()) }