fix: change project naming, create dummy sesame-vitale project

This commit is contained in:
theo
2024-07-24 21:59:24 +02:00
parent ff2c84fb33
commit 7d41fbb519
37 changed files with 56 additions and 31 deletions

27
crates/app/src/lib.rs Normal file
View File

@ -0,0 +1,27 @@
mod templates;
use std::path::Path;
use askama_axum::IntoResponse;
use templates::{hello::HelloResponse, index::GetIndexResponse};
use tower_http::services::ServeDir;
async fn root() -> impl IntoResponse {
return GetIndexResponse {}.into_response();
}
async fn hello() -> impl IntoResponse {
return HelloResponse {
name: "Theo".to_string(),
}
.into_response();
}
pub fn get_router(assets_path: &Path) -> axum::Router {
let router = axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.route("/hello", axum::routing::get(hello));
router
}

14
crates/app/src/main.rs Normal file
View File

@ -0,0 +1,14 @@
use ::app::get_router;
use std::path::Path;
use std::env;
#[tokio::main]
async fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let assets_path = Path::new(&manifest_dir).join("assets");
let router = get_router(assets_path.as_path());
// TODO: select port based on available port (or ask in CLI)
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, router).await.unwrap();
}

View File

@ -0,0 +1,7 @@
use askama::Template;
#[derive(Template)]
#[template(path = "hello.html")]
pub struct HelloResponse {
pub name: String,
}

View File

@ -0,0 +1,5 @@
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexResponse;

View File

@ -0,0 +1,2 @@
pub mod index;
pub mod hello;