M Cargo.lock => Cargo.lock +1 -0
@@ 577,6 577,7 @@ dependencies = [
"hyper",
"serde 1.0.131",
"serde_derive",
+ "serde_json",
"tokio",
]
M Cargo.toml => Cargo.toml +1 -0
@@ 9,6 9,7 @@ edition = "2021"
git2 = "0.13.25"
serde = "1.0.131"
serde_derive = "^1.0.131"
+serde_json = "1.0.73"
config = "0.11.0"
tokio = { version = "1", features = ["full"] }
hyper = { version = "0.14", features = ["full"] }=
\ No newline at end of file
M src/deploy.rs => src/deploy.rs +23 -4
@@ 1,10 1,29 @@
//use git2::Repository;
-use hyper::{Body, Response, Request};
-use std::convert::Infallible;
+use hyper::{Body, Response, Request, StatusCode, Method};
+use std::collections::HashMap;
use std::sync::Arc;
use crate::repoconf::RepoConf;
-pub async fn process(_b: Request<Body>, _rc: Arc<Vec<RepoConf>>) -> Result<Response<Body>, Infallible> {
- Ok(Response::new(Body::from("Hello World!\n")))
+pub async fn process(req: Request<Body>, _rc: Arc<Vec<RepoConf>>) -> Result<Response<Body>, hyper::Error> {
+ match (req.method(), req.uri().path()) {
+ (&Method::GET, "/") | (&Method::GET, "/index.html") => Ok(Response::new(Body::from("Hello world\n"))),
+ (&Method::POST, "/deploy") => deploy(req).await,
+ _ => {
+ // Return 404 not found response.
+ Ok(Response::builder()
+ .status(StatusCode::NOT_FOUND)
+ .body(Body::from("Not found\n"))
+ .unwrap())
+ }
+ }
+}
+
+async fn deploy(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
+ let bytes_stream = hyper::body::to_bytes(req).await?;
+ let _data: HashMap<String, String> = serde_json::from_slice(&bytes_stream).unwrap();
+
+ let res = Response::builder().status(StatusCode::default()).body(Body::from("Done.\n")).unwrap();
+
+ Ok(res)
}=
\ No newline at end of file