From 6a762589e2f557cb1b2096c6e8d888129c3e2fca Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Tue, 12 Nov 2024 20:53:18 +0100 Subject: basic routing for songs --- src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index af45779..9d6ec4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ -mod structs; 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 { @@ -11,9 +13,14 @@ struct AppState { #[actix_web::main] async fn main() -> std::io::Result<()> { + dotenv().ok(); let pool: MySqlPool = MySqlPoolOptions::new() .max_connections(10) - .connect(DB_URL) + .connect( + env::var("DATABASE_URL") + .expect("environment variables are *probably not setted up!!") + .as_str(), + ) .await .unwrap(); @@ -23,7 +30,7 @@ async fn main() -> std::io::Result<()> { App::new() .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) - .service(routes::hello::hello_actix) + .service(routes::song::song) }) .bind(("127.0.0.1", 8000))? .run() -- cgit v1.2.3