mod routes; mod structs; use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; use std::env; #[derive(Clone)] struct AppState { pool: MySqlPool, } #[actix_web::main] async fn main() -> std::io::Result<()> { dotenv().ok(); let pool: MySqlPool = MySqlPoolOptions::new() .max_connections(10) .connect( env::var("DATABASE_URL") .expect("environment variables are *probably not setted up!!") .as_str(), ) .await .unwrap(); let app_state = AppState { pool }; HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) .service(routes::song::song) }) .bind(("127.0.0.1", 8000))? .run() .await } async fn root() -> String { String::from("Server is up and running") }