ctoolbox/io/webui/
routes.rs

1//! Defines the web routes for the application.
2
3use axum::{Router, routing::get, routing::post};
4
5use crate::debug;
6use crate::io::webui::AppState;
7#[allow(clippy::wildcard_imports)]
8use crate::io::webui::controllers::*;
9
10pub fn build_routes(state: AppState) -> Router {
11    debug!("Building router");
12    // Build router
13    Router::new()
14        // --- web controller routes ---
15        .route("/", get(web::get_index))
16        .route("/privacy-policy", get(web::privacy_policy))
17        .route("/subscribe", get(web::subscribe))
18        // --- auth controller routes ---
19        .route("/login", get(auth::get_login).post(auth::post_login))
20        .route("/login-password", post(auth::post_login_password))
21        .route("/registration", post(auth::post_registration))
22        // --- app controller routes ---
23        .route(
24            "/pc-settings",
25            get(app::get_public_pc_settings).post(app::post_public_pc_settings),
26        )
27        .route("/home", get(app::get_home))
28        // --- search controller routes ---
29        .route("/search", get(search::get_index))
30        // --- graph controller routes ---
31        .route("/nodes", get(graph::get_nodes_index))
32        .route("/nodes/view", get(graph::get_nodes_view))
33        .route(
34            "/nodes/create",
35            get(graph::get_nodes_create).post(graph::post_nodes_create),
36        )
37        .route(
38            "/nodes/upload",
39            get(graph::get_nodes_upload).post(graph::post_nodes_upload),
40        )
41        // --- base controller routes (docs, css, static, fallback) ---
42        .route("/docs", get(base::get_doc_index))
43        .route("/docs/{*path}", get(base::get_doc_page))
44        .route("/app.css", get(base::get_app_css))
45        .route("/src.zip", get(base::get_src_zip))
46        .route("/dependencies.zip", get(base::get_dependencies_zip))
47        .route("/installer-linux-x64", get(base::get_installer_linux_x64))
48        // static files or 404 page fallback
49        .fallback(get(base::static_or_404))
50        .with_state(state)
51}
52
53pub fn base_url() -> String {
54    // TODO: Load from settings. See webui.rs for how to do this
55    "http://localhost:8080".to_string()
56}