fix: revert back to crates dir layout
This commit is contained in:
27
crates/clego/src/lib.rs
Normal file
27
crates/clego/src/lib.rs
Normal 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
|
||||
}
|
11
crates/clego/src/main.rs
Normal file
11
crates/clego/src/main.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use ::clego::get_router;
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let router = get_router(Path::new("/assets"));
|
||||
|
||||
// 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();
|
||||
}
|
7
crates/clego/src/templates/hello.rs
Normal file
7
crates/clego/src/templates/hello.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "hello.html")]
|
||||
pub struct HelloResponse {
|
||||
pub name: String,
|
||||
}
|
5
crates/clego/src/templates/index.rs
Normal file
5
crates/clego/src/templates/index.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct GetIndexResponse;
|
2
crates/clego/src/templates/mod.rs
Normal file
2
crates/clego/src/templates/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod index;
|
||||
pub mod hello;
|
Reference in New Issue
Block a user