aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..92d030a
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,47 @@
+
+use hyper::service::{make_service_fn, service_fn};
+use hyper::{Body, Client, Request, Response, Server, Uri};
+use std::net::SocketAddr;
+
+async fn upstream_req(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
+ println!("hit: {}", req.uri());
+ let req_uri = req.uri();
+ let upstream_uri = Uri::builder()
+ .scheme("http")
+ .authority("localhost:9200")
+ .path_and_query(req_uri.path_and_query().unwrap().as_str())
+ .build()
+ .unwrap();
+
+ let res = Client::new().get(upstream_uri).await?;
+ println!("resp!");
+ Ok(res)
+}
+
+async fn shutdown_signal() {
+ // Wait for the CTRL+C signal
+ tokio::signal::ctrl_c()
+ .await
+ .expect("failed to install CTRL+C signal handler");
+}
+
+async fn run_server(addr: SocketAddr) {
+ println!("Listening on http://{}", addr);
+
+ let serve_future = Server::bind(&addr)
+ .serve(make_service_fn(|_| async {
+ Ok::<_, hyper::Error>(service_fn(upstream_req))
+ }));
+ let graceful = serve_future.with_graceful_shutdown(shutdown_signal());
+
+ if let Err(e) = graceful.await {
+ eprintln!("server error: {}", e);
+ }
+}
+
+#[tokio::main]
+async fn main() {
+ let addr = SocketAddr::from(([127, 0, 0, 1], 3030));
+
+ run_server(addr).await;
+}