1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
}