29 lines
951 B
Rust
29 lines
951 B
Rust
#[derive(Debug, Clone)]
|
|
pub struct Config {
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub database_url: String,
|
|
pub jwt_secret: String,
|
|
pub cors_allowed_origins: Vec<String>,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> Self {
|
|
dotenvy::dotenv().ok();
|
|
Self {
|
|
host: std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string()),
|
|
port: std::env::var("PORT")
|
|
.ok()
|
|
.and_then(|p| p.parse().ok())
|
|
.unwrap_or(3000),
|
|
database_url: std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
|
|
jwt_secret: std::env::var("JWT_SECRET").expect("JWT_SECRET must be set"),
|
|
cors_allowed_origins: std::env::var("CORS_ALLOWED_ORIGINS")
|
|
.unwrap_or_else(|_| "http://localhost:3000".to_string())
|
|
.split(',')
|
|
.map(|s| s.trim().to_string())
|
|
.collect(),
|
|
}
|
|
}
|
|
}
|