diff --git a/src/main.rs b/src/main.rs index 872e94e..e2187bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,21 +4,30 @@ use axum::{ }; use askama_axum::Template; +#[tokio::main] +async fn main() { + let app = Router::new() + .route("/", get(index)) + .route("/hello", get(hello_world)); + + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} + +#[derive(Template)] +#[template(path = "index.html")] +struct IndexTemplate {} + +async fn index() -> IndexTemplate { + IndexTemplate {} +} + #[derive(Template)] #[template(path = "hello.html")] struct HelloTemplate<'a> { name: &'a str, } -#[tokio::main] -async fn main() { - let app = Router::new() - .route("/", get(hello_world)); - - let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); - axum::serve(listener, app).await.unwrap(); -} - async fn hello_world() -> HelloTemplate<'static> { HelloTemplate { name: "world" } } diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..42d8c7c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,12 @@ + +
+