From 96e900457e2d3b33aeacbd2c120afa439b1911ac Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 29 Jun 2020 20:12:07 -0400 Subject: [PATCH] cleanup default routing --- src/main.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index d8c4a55..2cc38d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,6 @@ fn debug_request(req: Request) -> BoxFut { Box::new(future::ok(response)) } -#[derive(Default)] struct RequestDetails { pub request_bytes: Vec, pub speaker: String, @@ -168,24 +167,15 @@ fn main() -> AnyhowResult<()> { info!("Got a request from: {:?}", remote_addr); let route_a = route_one.clone(); - let route_b = route_two.clone(); - service_fn(move |req: Request| { // returns BoxFut - match req.method() { - &Method::OPTIONS => { - // TODO: CORS should be hardcoded here, not wastefully proxied. - return hyper_reverse_proxy::call(remote_addr.ip(), &route_a, req); // Return BoxFut - }, - _ => {}, - } - - match req.uri().path() { - "/speak" => + service_fn(move |req: Request| { + match (req.method(), req.uri().path()) { + (&Method::POST, "/speak") => speak_proxy(req, remote_addr.clone(), "/speak"), - "/speak_spectrogram" => + (&Method::POST, "/speak_spectrogram") => speak_proxy(req, remote_addr.clone(), "/speak_spectrogram"), _ => - debug_request(req), + hyper_reverse_proxy::call(remote_addr.ip(), &route_a, req), } }) });