sysmonk/routes/
basics.rs

1use crate::{constant, squire};
2use actix_web::http::StatusCode;
3use actix_web::{web, HttpRequest, HttpResponse};
4use std::sync::Arc;
5
6/// Handles the health endpoint, returning a JSON response indicating the server is healthy.
7///
8/// # Returns
9///
10/// Returns an `HttpResponse` with a status of 200 (OK), content type "application/json",
11/// and a JSON body containing the string "Healthy".
12#[get("/health")]
13pub async fn health() -> HttpResponse {
14    HttpResponse::Ok()
15        .content_type("application/json")
16        .json("Healthy")
17}
18
19/// Handles the root endpoint, logging the connection and returning an HTML response.
20///
21/// # Arguments
22///
23/// * `request` - A reference to the Actix web `HttpRequest` object.
24/// * `session` - Session struct that holds the `session_mapping` to handle sessions.
25/// * `metadata` - Struct containing metadata of the application.
26/// * `template` - Configuration container for the loaded templates.
27///
28/// # Returns
29///
30/// Returns an `HttpResponse` with the index page as its body.
31#[get("/")]
32pub async fn root(request: HttpRequest,
33                  metadata: web::Data<Arc<constant::MetaData>>,
34                  template: web::Data<Arc<minijinja::Environment<'static>>>) -> HttpResponse {
35    squire::custom::log_connection(&request);
36    let index = template.get_template("index").unwrap();
37    HttpResponse::build(StatusCode::OK)
38        .content_type("text/html; charset=utf-8")
39        .body(index.render(minijinja::context!(version => &metadata.pkg_version)).unwrap())
40}