open rust.util inl parseUrls (uri : path_segments path_fmt) : () = inl get_locals () = ;[!>"> parseUrls ()"] inl log = new_log UnknownRustTarget (fun () => Debug) get_locals "006666" log Debug ;[!>"uri"; !>uri] () inl app () = inl get_locals () = ;[!>"> init ()"] inl log = new_log UnknownRustTarget (fun () => Debug) get_locals "666666" // emit_expr () $"\"#[macro_use] extern crate rocket\"" emit_expr () ($"\"\#[rocket::get(\\\"/\\\")]\"" /+ $"\" async fn proxy(\"" /+ $"\" uri: rocket::http::uri::Segments<'_, rocket::http::uri::fmt::Path>,\"" /+ $"\" client: &rocket::State\"" /+ $"\" ) -> Result, rocket::http::Status> {\"" /+ $"\" !parseUrls(uri.clone());\"" /+ // $"\" let uri = uri.clone();\"" /+ $"\" let uri = uri.collect::>();\"" /+ $"\" let uri = uri.join(\\\"/\\\");\"" /+ $"\" let uri = uri.replace(\\\":/\\\", \\\"://\\\");\"" /+ $"\" let (host_url, url) = uri.split_once('|').unwrap_or((\\\"\\\", &uri));\"" /+ $"\" let (host_protocol, host_host) = host_url.split_once(\\\"://\\\").unwrap_or((\\\"https\\\", \\\"www.github.com\\\"));\"" /+ $"\" let (protocol, suffix) = url.split_once(\\\"://\\\").unwrap_or((host_protocol, url));\"" /+ $"\" let (host, path) = match (url.split_once(\\\"://\\\"), suffix.split_once(\\\"/\\\")) {\"" /+ $"\" (Some(_), None) if suffix !!= \\\"\\\" => (suffix, \\\"\\\"),\"" /+ // $"\" (_, Some(url)) => url,\"" /+ $"\" _ => (host_host, suffix),\"" /+ $"\" };\"" /+ $"\" let new_url = match path {\"" /+ $"\" \\\"\\\" => format!!(\\\"{protocol}://{host}\\\"),\"" /+ $"\" _ => format!!(\\\"{protocol}://{host}/{path}\\\"),\"" /+ $"\" };\"" /+ $"\" println!!(\\\"uri={uri}; new_url={new_url}; host={host}; path={path}; suffix={suffix}; host_url={host_url}; url={url}; host_host={host_host}; host_protocol={host_protocol}; protocol={protocol}\\\");\"" /+ $"\" let res = client\"" /+ $"\" .get(new_url)\"" /+ $"\" .send()\"" /+ $"\" .await\"" /+ $"\" .map_err(|_| rocket::http::Status::NotFound);\"" /+ $"\" match res {\"" /+ $"\" Ok(res) => {\"" /+ $"\" let content = res.text();\"" /+ $"\" let content = content.await;\"" /+ $"\" let content = content.map_err(|_| rocket::http::Status::InternalServerError);\"" /+ $"\" let content = content.unwrap();\"" /+ $"\" Ok(rocket::response::content::RawHtml(content))\"" /+ $"\" }\"" /+ $"\" Err(status) => Err(status),\"" /+ $"\" }\"" /+ $"\"} ()\"") emit_expr () ($"\"\#[rocket::get(\\\"/file/\\\")]\"" /+ $"\" async fn file(\"" /+ $"\" file: std::path::PathBuf,\"" /+ $"\" client: &rocket::State\"" /+ $"\" ) -> std::option::Option {\"" /+ $"\" rocket::fs::NamedFile::open(std::path::Path::new(\\\"./\\\").join(file))\"" /+ $"\" .await\"" /+ $"\" .ok()\"" /+ $"\"} ()\"") emit_expr () ($"\"\#[rocket::launch]\"" /+ $"\" fn rocket() -> _ {\"" /+ $"\" rocket::build()\"" /+ $"\" .manage(reqwest::Client::new())\"" /+ $"\" .mount(\\\"/\\\", rocket::routes!![proxy, file])\"" /+ $"\"} ()\"") log Debug ;[!>"app end"; !>"???"] 0i32 inl main () = print_static "" app |> dyn |> ignore print_static ""