From 44833bc898cac0612907613ed64ee4ff2a94a5c8 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Mon, 20 Jan 2025 00:13:45 +0100 Subject: complete database rework --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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 } #[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) -- cgit v1.2.3