mode - Rename crate and update dependencies to newer versions - Add OFFLINE runtime mode for loopback-only server without DB - Refactor state handling with typed Axum routers and state injection - Rename mongodb module to mongo and fix imports accordingly - Update Cargo.lock with updated and removed dependencies - Remove no-auth feature and related code - Simplify health and user routes to generic state parameter Rename backend to purenotify_backend and add OFFLINE mode Use OFFLINE env var to run server without DB, binding to loopback only. Rename mongodb module to mongo and update dependencies. Update dependencies and fix router state handling.
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
// src/config.rs
|
|
|
|
use std::env;
|
|
use std::net::SocketAddr;
|
|
use std::str::FromStr;
|
|
|
|
use tracing::error;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Config {
|
|
pub bind_address: SocketAddr,
|
|
pub mongodb_uri: String,
|
|
pub database_name: String,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> Result<Self, String> {
|
|
let bind_address_str =
|
|
env::var("BIND_ADDRESS").unwrap_or_else(|_| "127.0.0.1:3000".to_string());
|
|
|
|
let bind_address = SocketAddr::from_str(&bind_address_str)
|
|
.map_err(|e| format!("Invalid BIND_ADDRESS: {}", e))?;
|
|
|
|
if bind_address.ip() != std::net::IpAddr::from([127, 0, 0, 1]) {
|
|
error!("In no-auth mode, BIND_ADDRESS must be 127.0.0.1");
|
|
return Err("In no-auth mode, BIND_ADDRESS must be 127.0.0.1".to_string());
|
|
}
|
|
|
|
let mongodb_uri =
|
|
env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://localhost:27017".to_string());
|
|
|
|
let database_name = env::var("DATABASE_NAME").unwrap_or_else(|_| "purenotify".to_string());
|
|
|
|
Ok(Self {
|
|
bind_address,
|
|
mongodb_uri,
|
|
database_name,
|
|
})
|
|
}
|
|
}
|