diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 5f49165..f400920 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ use crate::frontend::style::CSS_BUNDLE; use actix_web::{get, web, App, HttpServer, Responder}; +use database::Database; use frontend::pages::home::page_home; +pub mod database; pub mod frontend; +pub mod library; #[get("/assets/style.css")] async fn assets_style() -> impl Responder { @@ -14,11 +17,24 @@ async fn hello(name: web::Path<String>) -> impl Responder { format!("Hello {}!", &name) } +pub struct AppState { + pub database: Database, +} + #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env("LOG"); - HttpServer::new(|| App::new().service(page_home).service(hello)) - .bind(("127.0.0.1", 8080))? - .run() - .await + let db_path = std::env::var("DB_PATH").unwrap_or("data/db".to_string()); + let state = web::Data::new(AppState { + database: Database::open(&db_path).unwrap().into(), + }); + HttpServer::new(move || { + App::new() + .app_data(state.clone()) + .service(page_home) + .service(hello) + }) + .bind(("127.0.0.1", 8080))? + .run() + .await } |