blob: f4009207f7fd3a3ae09a669df97a5d0e481eeca9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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 {
CSS_BUNDLE
}
#[get("/{name}")]
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");
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
}
|