rumtk_web/utils/
matcher.rs1use crate::components::app_shell::app_shell;
24use crate::rumtk_web_get_component;
25use crate::utils::defaults::DEFAULT_ROBOT_TXT;
26use crate::utils::types::SharedAppConf;
27use crate::utils::{HTMLResult, RUMString};
28use axum::response::Html;
29use std::collections::HashMap;
30
31pub async fn default_robots_matcher(
32 _path: Vec<RUMString>,
33 _params: HashMap<RUMString, RUMString>,
34 _state: SharedAppConf,
35) -> HTMLResult {
36 Ok(Html::<String>::from(String::from(DEFAULT_ROBOT_TXT)))
37}
38
39pub async fn default_page_matcher(
40 path: Vec<RUMString>,
41 params: HashMap<RUMString, RUMString>,
42 state: SharedAppConf,
43) -> HTMLResult {
44 let path_components = match path.first() {
45 Some(x) => x.split('/').collect::<Vec<&str>>(),
46 None => Vec::new(),
47 };
48
49 app_shell(&path_components, ¶ms, state.clone())
51}
52
53pub async fn default_component_matcher(
54 path: Vec<RUMString>,
55 params: HashMap<RUMString, RUMString>,
56 state: SharedAppConf,
57) -> HTMLResult {
58 let path_components = match path.first() {
59 Some(x) => x.split('/').collect::<Vec<&str>>(),
60 None => Vec::new(),
61 };
62
63 let component = match path_components.first() {
64 Some(component) => component,
65 None => return Err(RUMString::from("Missing component name to fetch!")),
66 };
67
68 let component = rumtk_web_get_component!(component);
69
70 component(&path_components[1..], ¶ms, state.clone())
71}