pict-rs-aggregator/src/main.rs
2021-09-06 15:44:01 -05:00

35 lines
972 B
Rust

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<dyn std::error::Error>> {
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 db = sled::open("sled/db-0-34")?;
let config = pict_rs_aggregator::Config::from_args();
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(())
}