diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-02 15:48:39 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-02 15:48:39 +0100 |
commit | cea871d944e36222f5fdabe3e907cb8cf86d26e8 (patch) | |
tree | a2928e83176e21f19fe9dc319c6753677742cb4a /src/web/web_server.rs | |
parent | 104e2ce0a25917dfaaab7e62042cc611fc05125a (diff) | |
download | garage-cea871d944e36222f5fdabe3e907cb8cf86d26e8.tar.gz garage-cea871d944e36222f5fdabe3e907cb8cf86d26e8.zip |
Skeleton to the new web API
Diffstat (limited to 'src/web/web_server.rs')
-rw-r--r-- | src/web/web_server.rs | 37 |
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(()) +} |