this repo has no description
at content-sections 30 lines 669 B view raw
1use sqlx::SqlitePool; 2 3#[derive(Clone)] 4pub struct AppState { 5 pub db: SqlitePool, 6 pub jwt_secret: String, 7} 8 9impl AppState { 10 pub fn from_env(db: SqlitePool) -> Self { 11 let jwt_secret = 12 std::env::var("JWT_SECRET").unwrap_or_else(|_| "dev-secret-change-me".to_string()); 13 Self { db, jwt_secret } 14 } 15} 16 17pub fn database_url() -> String { 18 std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite:ayos.db".to_string()) 19} 20 21pub fn static_dir() -> Option<String> { 22 std::env::var("STATIC_DIR").ok() 23} 24 25pub fn port() -> u16 { 26 std::env::var("PORT") 27 .ok() 28 .and_then(|p| p.parse().ok()) 29 .unwrap_or(3001) 30}