use actix_web::{web, App, HttpServer}; use sea_orm::{Database, DatabaseConnection}; use tracing::{info, instrument}; use tracing_subscriber::prelude::*; mod api; mod entity; mod error; #[derive(Debug)] pub struct AppState { pub db: DatabaseConnection, } #[actix_web::main] async fn main() { let subscriber = tracing_subscriber::registry().with( tracing_subscriber::fmt::Layer::new() .pretty() .with_writer(std::io::stdout) .with_ansi(true) .with_filter(tracing_subscriber::filter::LevelFilter::DEBUG), ); tracing::subscriber::set_global_default(subscriber).expect("Unable to set a global collector"); let db = setup_database().await.unwrap(); let state = web::Data::new(AppState { db }); info!("Starting http server on 8080"); HttpServer::new(move || { App::new() .app_data(state.clone()) .service(api::applications::routes()) .service(api::application_categories::routes()) .service(api::bookmarks::routes()) .service(api::bookmark_categories::routes()) }) .bind("127.0.0.1:8080") .unwrap() .run() .await .expect("Couldnt launch server"); } #[instrument] async fn setup_database() -> Result { Database::connect("sqlite://data.db").await }