39 lines
908 B
Rust
39 lines
908 B
Rust
use askama::Template;
|
|
use askama_axum::IntoResponse;
|
|
use axum::{routing::get, Router};
|
|
use tower_http::services::ServeDir;
|
|
|
|
// Represents the currently logged-in user, passed into every template.
|
|
// None = logged out.
|
|
pub struct CurrentUser {
|
|
pub username: String,
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "index.html")]
|
|
struct IndexTemplate {
|
|
title: String,
|
|
current_user: Option<CurrentUser>,
|
|
}
|
|
|
|
async fn index() -> impl IntoResponse {
|
|
IndexTemplate {
|
|
title: "home".into(),
|
|
current_user: None, // no auth yet
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let app = Router::new()
|
|
.route("/", get(index))
|
|
.nest_service("/static", ServeDir::new("static"));
|
|
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
|
.await
|
|
.unwrap();
|
|
|
|
println!("listening on http://127.0.0.1:3000");
|
|
axum::serve(listener, app).await.unwrap();
|
|
}
|