From b76338f8024d79e376b01d0abb78198c53743732 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 14 Jul 2021 07:44:35 +0200 Subject: [PATCH] config --- src/gitust.rs | 3 +++ src/main.rs | 31 +++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/gitust.rs diff --git a/src/gitust.rs b/src/gitust.rs new file mode 100644 index 0000000..b19b713 --- /dev/null +++ b/src/gitust.rs @@ -0,0 +1,3 @@ +pub struct Gitust { + pub repo_root_path : String, +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b840793..e80eaf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod git; mod ite; mod reader; mod writer; +mod gitust; use actix_files::Files; use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Error, HttpRequest, HttpMessage}; @@ -33,6 +34,7 @@ use actix_web::http::header::IntoHeaderValue; use actix_web::client::PayloadError; use crate::reader::ToStream; use crate::writer::Writer; +use crate::gitust::Gitust; #[derive(Template)] #[template(path = "hello.html")] @@ -115,7 +117,7 @@ async fn chunk() -> HttpResponse { return; }; - while true { + loop { tokio::time::delay_for(std::time::Duration::from_secs(1)).await; println!("send message"); tx.send(Ok(Bytes::from_static(b"coucou"))); @@ -126,7 +128,11 @@ async fn chunk() -> HttpResponse { } #[get("/git/{owner}/{repo}.git")] -async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query) -> impl Responder { +async fn git_main( + web::Path((owner, reponame)): web::Path<(String, String)>, + web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query, + gitust : web::Data +) -> impl Responder { let commitname = match commitnameopt { None => {"master".to_string()} Some(s) => {s} @@ -149,22 +155,20 @@ async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)} } //#[get("/git/{owner}/{repo}.git/{path:.*}")] -async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web::Path<(String, String)>, mut req: HttpRequest) -> io::Result{ +async fn git_proto( + mut payload : web::Payload, + web::Path((owner, reponame)): web::Path<(String, String)>, + mut req: HttpRequest, + gitust : web::Data +) -> io::Result{ //println!("enter git_proto"); let mut cmd = Command::new("git"); cmd.arg("http-backend"); // Required environment variables cmd.env("REQUEST_METHOD", req.method().as_str()); - cmd.env("GIT_PROJECT_ROOT", "/home/hubert"); - cmd.env( - "PATH_INFO", - if req.path().starts_with('/') { - req.path().to_string() - } else { - format!("/{}", req.path()) - }, - ); + cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path); + cmd.env("PATH_INFO", format!("/{}/{}.git",owner, reponame)); cmd.env("REMOTE_USER", ""); //cmd.env("REMOTE_ADDR", req.remote_addr().to_string()); cmd.env("QUERY_STRING", req.query_string()); @@ -283,6 +287,9 @@ async fn main() -> std::io::Result<()> { HttpServer::new(|| { let auth = HttpAuthentication::basic(basic_auth_validator); App::new() + .data(Gitust { + repo_root_path: "/home/hubert/gitust".to_string(), + }) .wrap(Logger::default()) // .wrap(Logger::new("%a %{User-Agent}i")) .wrap(CookieSession::signed(&[0; 32]).secure(false))