aboutsummaryrefslogtreecommitdiff
path: root/src/web/web_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/web_server.rs')
-rw-r--r--src/web/web_server.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
new file mode 100644
index 00000000..cb81e433
--- /dev/null
+++ b/src/web/web_server.rs
@@ -0,0 +1,37 @@
+use std::sync::Arc;
+
+use futures::future::Future;
+
+use hyper::server::conn::AddrStream;
+use hyper::{Body,Request,Response,Server};
+use hyper::service::{make_service_fn, service_fn};
+
+use garage_util::error::Error;
+use garage_model::garage::Garage;
+
+pub async fn run_web_server(
+ garage: Arc<Garage>,
+ shutdown_signal: impl Future<Output = ()>,
+) -> Result<(), Error> {
+ let addr = &garage.config.s3_web.web_bind_addr;
+
+ let service = make_service_fn(|conn: &AddrStream| {
+ let garage = garage.clone();
+ let client_addr = conn.remote_addr();
+ info!("{:?}", client_addr);
+ async move {
+ Ok::<_, Error>(service_fn(move |req: Request<Body>| {
+ let garage = garage.clone();
+ //handler(garage, req, client_addr)
+ async move { Ok::<Response<Body>, Error>(Response::new(Body::from("hello world\n"))) }
+ }))
+ }
+ });
+
+ let server = Server::bind(&addr).serve(service);
+ let graceful = server.with_graceful_shutdown(shutdown_signal);
+ info!("Web server listening on http://{}", addr);
+
+ graceful.await?;
+ Ok(())
+}