use actix_web::{middleware::Logger, App, HttpServer}; use awc::Client; use std::time::Duration; use structopt::StructOpt; #[actix_web::main] async fn main() -> Result<(), Box> { if std::env::var("RUST_LOG").is_err() { std::env::set_var("RUST_LOG", "info,pict_rs_aggregator=info,actix_web=info"); } env_logger::init(); let config = pict_rs_aggregator::Config::from_args(); let mut db_path = config.db_path().to_owned(); db_path.push("sled"); db_path.push("db-0-34"); let db = sled::open(db_path)?; let bind_address = config.bind_address(); let state = pict_rs_aggregator::state(config, "", db)?; HttpServer::new(move || { let client = Client::builder() .timeout(Duration::from_secs(30)) .header("User-Agent", "pict_rs_aggregator-v0.1.0") .finish(); App::new() .wrap(Logger::default()) .service(pict_rs_aggregator::service(client, state.clone())) }) .bind(bind_address)? .run() .await?; Ok(()) }