#![feature(try_blocks)] use axum::{ extract::Path, http::Uri, response::{Html, IntoResponse, Response}, routing::get, Router, }; use reqwest::StatusCode; fn router() -> Router { Router::new().route("/{*k}", get(root)) } pub async fn root(uri: Uri) -> Response { let url = [ &uri.path()[1..], &uri.query().map_or("".to_string(), |x| "?".to_string() + x), ] .concat(); let Ok::(svg) = (try { reqwest::get(&url).await?.text().await? }) else { return (StatusCode::IM_A_TEAPOT, url).into_response(); }; Html(include_str!("../index.html").replace("@svg", &(svg + &url))).into_response() } #[tokio::main] async fn main() { axum::serve( tokio::net::TcpListener::bind("0.0.0.0:3333").await.unwrap(), router().into_make_service(), ) .await .unwrap(); }