sarmentine/src/main.rs
2026-04-07 21:41:39 -04:00

48 lines
1.0 KiB
Rust

mod db;
use askama::Template;
use askama_axum::IntoResponse;
use axum::{routing::get, Router};
use sqlx::SqlitePool;
use tower_http::services::ServeDir;
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,
}
}
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let database_url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "sqlite:./sarmentine.db".into());
let pool: SqlitePool = db::connect(&database_url).await;
let app = Router::new()
.route("/", get(index))
.nest_service("/static", ServeDir::new("static"))
.with_state(pool);
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();
}