mod database; mod routes; mod structs; use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use std::sync::Arc; #[derive(Clone)] struct AppState { 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 db_raw = match database::DatabaseWrapper::new().await { Ok(res) => res, Err(_) => panic!("Error creating database wrapper"), }; let db = Arc::new(db_raw); let app_state = AppState { database: db }; HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) .service(routes::song::get_song) .service(routes::song::post_song) .service(routes::song::put_song) .service(routes::song::delete_song) .service(routes::album::get_album) .service(routes::album::post_album) .service(routes::album::put_album) .service(routes::album::delete_album) .service(routes::artist::get_artist) .service(routes::artist::post_artist) .service(routes::artist::put_artist) .service(routes::artist::delete_artist) .service(routes::search_results::search_results) }) .bind(("127.0.0.1", 8000))? .run() .await } async fn root() -> String { String::from("Server is up and running") }