diff --git a/src/data.rs b/src/data.rs new file mode 100644 index 0000000..2eef40b --- /dev/null +++ b/src/data.rs @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +use actix_web::web; +use reqwest::Client; + +#[derive(Clone)] +pub struct Data { + pub client: Client, +} + +pub type AppData = web::Data; + +impl Data { + pub fn new() -> AppData { + AppData::new(Self { + client: Client::new(), + }) + } +} diff --git a/src/main.rs b/src/main.rs index 816b88b..2df4c68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,11 +23,14 @@ use actix_web::{ use lazy_static::lazy_static; use log::info; +mod data; mod meta; mod proxy; mod routes; mod settings; +pub use data::AppData; +pub use data::Data; pub use routes::ROUTES as V1_API_ROUTES; pub use settings::Settings; @@ -57,6 +60,8 @@ async fn main() -> std::io::Result<()> { println!("Starting server on: http://{}", SETTINGS.server.get_ip()); + let data = Data::new(); + HttpServer::new(move || { App::new() .wrap(actix_middleware::Logger::default()) @@ -69,6 +74,7 @@ async fn main() -> std::io::Result<()> { .wrap(actix_middleware::NormalizePath::new( actix_middleware::TrailingSlash::Trim, )) + .app_data(data.clone()) .configure(services) }) .workers(SETTINGS.server.workers.unwrap_or_else(num_cpus::get))