aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-09 22:53:14 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-09 22:53:14 +0100
commitc64d3cd8cda389909b4b3dbdf00c0710e2c9a490 (patch)
treec0c5f8a077d4ca0c627f3f50b5f6690b86909681 /src/main.rs
parent1599b61d22810e250f471b3b561660205297e07c (diff)
downloadjellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar
jellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar.bz2
jellything-c64d3cd8cda389909b4b3dbdf00c0710e2c9a490.tar.zst
a
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
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
}