(server_req: Request<Body>)
| 11 | |
| 12 | #[wstd::http_server] |
| 13 | async fn main(server_req: Request<Body>) -> Result<Response<Body>, Error> { |
| 14 | match server_req.uri().path_and_query().unwrap().as_str() { |
| 15 | api_prefixed_path if api_prefixed_path.starts_with(PROXY_PREFIX) => { |
| 16 | // Remove PROXY_PREFIX |
| 17 | let target_url = |
| 18 | std::env::var("TARGET_URL").expect("missing environment variable TARGET_URL"); |
| 19 | let target_url: Uri = format!( |
| 20 | "{target_url}{}", |
| 21 | api_prefixed_path |
| 22 | .strip_prefix(PROXY_PREFIX) |
| 23 | .expect("checked above") |
| 24 | ) |
| 25 | .parse() |
| 26 | .expect("final target url should be parseable"); |
| 27 | println!("Proxying to {target_url}"); |
| 28 | proxy(server_req, target_url).await |
| 29 | } |
| 30 | _ => Ok(http_not_found(server_req)), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | async fn proxy(server_req: Request<Body>, target_url: Uri) -> Result<Response<Body>, Error> { |
| 35 | let client = Client::new(); |
nothing calls this directly
no test coverage detected