diff --git a/src/main.rs b/src/main.rs index 594bf295..0436dec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,14 @@ extern crate markdown; +use std::sync::Mutex; + use actix_web::middleware::Logger; -use actix_web::{App, HttpServer}; +use actix_web::{App, HttpServer, web}; use env_logger; pub(crate) mod b64; pub(crate) mod core; +pub(crate) mod db; pub(crate) mod external_services; pub(crate) mod parsers; pub(crate) mod router; @@ -26,13 +29,19 @@ pub(crate) mod router; #[tokio::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug")); + let client =match db::setup::setup().await { + Ok(client) => client, + Err(e) => panic!("Error setting up database: {}", e), + }; + let state = web::Data::new(Mutex::new(client)); HttpServer::new(move || { let cors = actix_cors::Cors::default() .allow_any_origin() .allow_any_method() .allow_any_header(); App::new() + .app_data(state.clone()) .wrap(Logger::default()) .wrap(cors) .service(router::health) diff --git a/src/router/logs.rs b/src/router/logs.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/router/mod.rs b/src/router/mod.rs index e0aa77cb..f781cc9b 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -1,3 +1,5 @@ +use std::sync::Mutex; + use actix_web::{get, HttpResponse, Responder}; pub mod application; @@ -5,6 +7,10 @@ pub mod blockchain; /// Return server health status #[get("/health")] -pub async fn health() -> impl Responder { - HttpResponse::Ok().body("OK") +pub async fn health(client: actix_web::web::Data>) -> impl Responder { + let client = client.lock().unwrap(); + match crate::db::setup::db_health_check(client.clone()).await { + Ok(_) => HttpResponse::Ok().body("OK"), + Err(e) => HttpResponse::InternalServerError().body(format!("Error: {}", e)), + } }