2024-04-12 09:08:43 +02:00
|
|
|
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
|
2024-04-09 14:30:10 +02:00
|
|
|
mod config;
|
|
|
|
mod proxy;
|
2024-04-12 08:39:51 +02:00
|
|
|
use proxy::Mirror;
|
2024-04-09 14:30:10 +02:00
|
|
|
|
|
|
|
async fn index(req: HttpRequest) -> impl Responder {
|
|
|
|
let path = req.path();
|
2024-04-12 08:39:51 +02:00
|
|
|
let p: &actix_web::web::Data<Mirror> = req.app_data().unwrap();
|
2024-04-09 14:30:10 +02:00
|
|
|
|
|
|
|
let data = p.get(path, &req).await;
|
2024-04-12 09:08:43 +02:00
|
|
|
data.unwrap_or_else(|| HttpResponse::NotFound().finish())
|
2024-04-09 14:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let proxym = {
|
|
|
|
let config: config::Config =
|
2024-04-12 08:28:04 +02:00
|
|
|
toml::from_str(&std::fs::read_to_string("./mirrord.conf").unwrap()).unwrap();
|
2024-04-09 14:30:10 +02:00
|
|
|
config.to_proxy()
|
|
|
|
};
|
|
|
|
|
|
|
|
let proxym = actix_web::web::Data::new(proxym);
|
|
|
|
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.wrap(actix_web::middleware::Logger::default())
|
|
|
|
.app_data(proxym.clone())
|
|
|
|
.service(web::resource("/{path:.*}").to(index))
|
|
|
|
})
|
|
|
|
.bind("0.0.0.0:8080")?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|