use axum::{Router, response::Html, routing::get}; use std::{fs::OpenOptions, io::Read}; type Error = Box; type Result = std::result::Result; #[tokio::main] async fn main() -> Result<()> { // build our application with a single route let app = Router::new() .route("/", get(serve_path("./routes/root/index.html")?)) .route("/who", get(serve_path("./routes/who/index.html")?)) .route("/contact", get(serve_path("./routes/contact/index.html")?)) // .route("/api/pubkey", get(todo!())); ; // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); Ok(()) } fn serve_path(path: impl AsRef) -> Result> { let mut s = String::new(); OpenOptions::new() .read(true) .write(false) .open(path)? .read_to_string(&mut s)?; Ok(Html(s)) }