This repository has been archived on 2024-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
staxman-old/src/route/mod.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2023-11-18 17:52:15 +01:00
use crate::{
2023-11-18 20:51:10 +01:00
http::{
error::AppError,
response::{reply, HandlerResponse},
},
node::{
stack::{list, NodeInfo},
system::{system_info, SystemInfo},
},
2023-11-18 20:51:10 +01:00
AppState,
2023-11-18 17:52:15 +01:00
};
2023-11-19 15:08:47 +01:00
use askama::Template;
use axum::{extract::State, response::IntoResponse, routing::get, Json, Router};
2023-11-19 15:08:47 +01:00
use serde_json::json;
2023-11-18 16:35:30 +01:00
2023-11-23 14:18:00 +01:00
use self::assets::static_path;
mod assets;
2023-11-19 15:08:47 +01:00
mod container;
2023-11-18 20:51:10 +01:00
mod stack;
2023-11-18 16:35:30 +01:00
#[derive(Template)]
#[template(path = "home.html")]
struct HomeTemplate {
info: NodeInfo,
system: SystemInfo,
2023-11-18 16:35:30 +01:00
}
2023-11-18 20:51:10 +01:00
async fn home(State(state): State<AppState>) -> HandlerResponse {
let info = list(&state.stack_dir, &state.docker)
2023-11-18 16:35:30 +01:00
.await
.map_err(AppError::from)?;
let system = system_info();
reply(
json!({ "info": info, "system": system }),
HomeTemplate { info, system },
)
}
async fn get_sys_info() -> impl IntoResponse {
Json(system_info())
2023-11-18 16:35:30 +01:00
}
2023-11-18 20:51:10 +01:00
pub(crate) fn router() -> Router<AppState> {
Router::new()
2023-11-23 14:18:00 +01:00
.route("/static/*path", get(static_path))
2023-11-18 20:51:10 +01:00
.route("/", get(home))
.route("/sysinfo", get(get_sys_info))
2023-11-18 20:51:10 +01:00
.nest("/stack", stack::router())
2023-11-19 15:08:47 +01:00
.nest("/container", container::router())
2023-11-18 16:35:30 +01:00
}