From 9394657613014891ff91db6cd0a01b21bb257053 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 4 Nov 2025 10:42:18 +0000 Subject: feat: implement NIP-01 compliant Nostr relay - WebSocket-based relay using tokio-tungstenite - Full NIP-01 protocol support (EVENT, REQ, CLOSE) - Event validation (signature and ID) - In-memory event storage - Filter support (IDs, authors, kinds, since/until) - Configuration via environment variables - Nix flake for reproducible builds - Test automation script All 6 NIP-01 smoke tests passing (100%) --- src/config.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..252873d --- /dev/null +++ b/src/config.rs @@ -0,0 +1,38 @@ +use anyhow::{Context, Result}; +use serde::{Deserialize, Serialize}; +use std::env; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub domain: String, + pub owner_npub: String, + pub relay_name: String, + pub relay_description: String, + pub git_data_path: String, + pub relay_data_path: String, + pub bind_address: String, +} + +impl Config { + pub fn from_env() -> Result { + // Load .env file if present + dotenvy::dotenv().ok(); + + Ok(Config { + domain: env::var("NGIT_DOMAIN") + .unwrap_or_else(|_| "localhost:8080".to_string()), + owner_npub: env::var("NGIT_OWNER_NPUB") + .context("NGIT_OWNER_NPUB must be set")?, + relay_name: env::var("NGIT_RELAY_NAME") + .unwrap_or_else(|_| "ngit-grasp relay".to_string()), + relay_description: env::var("NGIT_RELAY_DESCRIPTION") + .unwrap_or_else(|_| "A GRASP-compliant Nostr relay for Git".to_string()), + git_data_path: env::var("NGIT_GIT_DATA_PATH") + .unwrap_or_else(|_| "./data/git".to_string()), + relay_data_path: env::var("NGIT_RELAY_DATA_PATH") + .unwrap_or_else(|_| "./data/relay".to_string()), + bind_address: env::var("NGIT_BIND_ADDRESS") + .unwrap_or_else(|_| "127.0.0.1:8080".to_string()), + }) + } +} -- cgit v1.2.3