aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-04-14 18:29:03 -0700
committerFuwn <[email protected]>2022-04-14 18:29:03 -0700
commit97b08663354d5f2c494151bcd97d40475ee8d3b7 (patch)
treeec53d4348bbfa03c4faa9e83fcf2378e8947b9a3 /src/main.rs
parentfeat: route fixing (diff)
downloadlocus-97b08663354d5f2c494151bcd97d40475ee8d3b7.tar.xz
locus-97b08663354d5f2c494151bcd97d40475ee8d3b7.zip
feat: sitemap
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 28f8ff3..5404af9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -61,6 +61,8 @@ static DATABASE: SyncLazy<Mutex<PickleDb>> = SyncLazy::new(|| {
}
})
});
+static ROUTES: SyncLazy<Mutex<Vec<String>>> =
+ SyncLazy::new(|| Mutex::new(vec![]));
#[derive(Template)]
#[template(path = "main")]
@@ -82,6 +84,15 @@ fn hits_from_route(route: &str) -> i32 {
}
}
+fn track_mount(
+ router: &mut Router,
+ route: &str,
+ handler: windmark::handler::RouteResponse,
+) {
+ (*ROUTES.lock().unwrap()).push(route.to_string());
+ router.mount(route, handler);
+}
+
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("RUST_LOG", "windmark,locus=trace");
@@ -132,7 +143,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
}));
router.set_fix_path(true);
- router.mount(
+ track_mount(
+ &mut router,
"/uptime",
Box::new(move |context| {
success!(
@@ -171,5 +183,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
time_mount.elapsed().as_nanos() as f64 / 1_000_000.0
);
+ track_mount(
+ &mut router,
+ "/sitemap",
+ Box::new(|context| {
+ success!(
+ format!(
+ "# SITEMAP\n\n{}",
+ (*ROUTES.lock().unwrap())
+ .iter()
+ .map(|r| format!("=> {}", r))
+ .collect::<Vec<_>>()
+ .join("\n")
+ ),
+ context
+ )
+ }),
+ );
+
router.run().await
}