Files
guru-connect/server/src/config.rs
Mike Swanson f6bf0cfd26 Add PostgreSQL database persistence
- Add connect_machines, connect_sessions, connect_session_events, connect_support_codes tables
- Implement db module with connection pooling (sqlx)
- Add machine persistence across server restarts
- Add audit logging for session/viewer events
- Support codes now persisted to database

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 19:51:01 -07:00

54 lines
1.4 KiB
Rust

//! Server configuration
use anyhow::Result;
use serde::Deserialize;
use std::env;
#[derive(Debug, Clone, Deserialize)]
pub struct Config {
/// Address to listen on (e.g., "0.0.0.0:8080")
pub listen_addr: String,
/// Database URL (optional - server works without it)
pub database_url: Option<String>,
/// Maximum database connections in pool
pub database_max_connections: u32,
/// JWT secret for authentication
pub jwt_secret: Option<String>,
/// Enable debug logging
pub debug: bool,
}
impl Config {
/// Load configuration from environment variables
pub fn load() -> Result<Self> {
Ok(Self {
listen_addr: env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0:8080".to_string()),
database_url: env::var("DATABASE_URL").ok(),
database_max_connections: env::var("DATABASE_MAX_CONNECTIONS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(5),
jwt_secret: env::var("JWT_SECRET").ok(),
debug: env::var("DEBUG")
.map(|v| v == "1" || v.to_lowercase() == "true")
.unwrap_or(false),
})
}
}
impl Default for Config {
fn default() -> Self {
Self {
listen_addr: "0.0.0.0:8080".to_string(),
database_url: None,
database_max_connections: 5,
jwt_secret: None,
debug: false,
}
}
}