Routing WiP

This commit is contained in:
Pascal Engélibert 2026-01-31 20:43:08 +01:00
commit a2bd5eb869
6 changed files with 588 additions and 2 deletions

30
src/server.rs Normal file
View file

@ -0,0 +1,30 @@
use std::collections::HashMap;
use trillium::{Conn, Handler};
use trillium_router::{Router, RouterConnExt};
pub async fn hello_world(conn: Conn) -> Conn {
conn.ok("hello world!")
}
pub fn make_router() -> impl Handler {
(trillium_caching_headers::CachingHeaders::new(),
trillium_static_compiled::static_compiled!("./static").with_index_file("index.html"),
Router::new()
.post("/fetch", |mut conn: Conn| async move {
if let Ok(request_body) = conn.request_body().await.with_max_len(8192).await {
let mut repo_url = None;
for (key, val) in form_urlencoded::parse(request_body.as_bytes()) {
if key == "repo-url" {
repo_url = Some(val);
}
}
let Some(repo_url) = repo_url else {
return conn.ok("Missing arg");
};
}
//let planet = conn.param("planet").unwrap();
let response_body = format!("hello");
conn.ok(response_body)
}))
}