diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-20 00:13:45 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-20 00:13:45 +0100 |
commit | 44833bc898cac0612907613ed64ee4ff2a94a5c8 (patch) | |
tree | 5bb8f355ebeabeead47495f05d00a186d2e06960 /src/main.rs | |
parent | ed0f5925de1931a13e6713d73e174a5362fc5d68 (diff) |
complete database rework
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index f1a58ec..5226692 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,20 +6,26 @@ use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use std::sync::Arc; +#[derive(Clone)] struct AppState { - database: database::DatabaseWrapper + database: Arc<database::DatabaseWrapper> } #[actix_web::main] async fn main() -> std::io::Result<()> { + // Errors can get very tough, + // the rust log saved my ass + std::env::set_var("RUST_LOG", "debug"); + env_logger::init(); dotenv().ok(); - let app_state_raw = database::DatabaseWrapper::new().await.expect("Something went wrong -- DatabaseWrapper::new()"); - let app_state = Arc::new(app_state_raw); + let db_raw = database::DatabaseWrapper::new().await.expect("Something went wrong -- DatabaseWrapper::new()"); + let db = Arc::new(db_raw); + let app_state = AppState{database: db}; HttpServer::new(move || { App::new() - .app_data(web::Data::new(Arc::clone(&app_state))) + .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) .service(routes::song::song) .service(routes::album::album) |