use genenetwork4::config::DbMode; #[tokio::main] async fn main() { let config = genenetwork4::config::Config::load(); // Startup database probe (`SELECT 1` through the shared pool), // BEFORE the listener is bound. `production` treats an unreachable // database as a misconfiguration and refuses to start; `dev` starts // anyway, loudly, with DB-backed routes answering the typed 503 // (src/error.rs). The message names both config keys so the refusal // is unambiguous. if let Err(error) = genenetwork4::db::probe() { match config.db_mode { DbMode::Production => { eprintln!( "FATAL: GN4_DB_MODE=production requires a reachable database, but SQL_URI \ is unreachable or unconfigured ({error}); refusing to start." ); std::process::exit(1); } DbMode::Dev => { eprintln!( "database not configured/unreachable — DB-backed routes disabled \ (GN4_DB_MODE=dev, SQL_URI unreachable or unconfigured): {error}" ); } } } let bind_ip: std::net::IpAddr = config .bind .parse() .expect("GENENETWORK4_BIND must be an IP address"); let addr = std::net::SocketAddr::new(bind_ip, config.port); let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); // The connect info (the peer's address) is what POST /get-test-token // checks to answer only local callers (src/routes/dev.rs). axum::serve( listener, genenetwork4::app().into_make_service_with_connect_info::(), ) .await .unwrap(); }