Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..fedece7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ +#![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::<String, anyhow::Error>(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(); +} |