diff --git a/src/handlers/error.rs b/src/handlers/error.rs index a475d23..0aaa543 100644 --- a/src/handlers/error.rs +++ b/src/handlers/error.rs @@ -45,7 +45,6 @@ fn make_body(code: Option, message: Option<&str>) -> String { .0 } -#[expect(clippy::unused_async)] pub async fn not_found() -> Response { by_code( Some(404), diff --git a/src/handlers/graph.rs b/src/handlers/graph.rs index 209e9b6..8b16b69 100644 --- a/src/handlers/graph.rs +++ b/src/handlers/graph.rs @@ -2,7 +2,6 @@ use axum::{body::Body, extract::Path, http::Response}; use crate::{formats::populate_graph, handlers, types::Node}; -#[expect(clippy::unused_async)] pub async fn node(Path(id): Path) -> Response { let mut context = tera::Context::new(); diff --git a/src/handlers/navigation.rs b/src/handlers/navigation.rs index fb4444a..cdfdec7 100644 --- a/src/handlers/navigation.rs +++ b/src/handlers/navigation.rs @@ -20,7 +20,6 @@ pub async fn nexus(template: &str) -> Response { handlers::template::by_filename(template, &context, 500, None, false) } -#[expect(clippy::unused_async)] pub async fn search(Form(query): Form) -> Redirect { Redirect::permanent(format!("/node/{}", query.node).as_str()) } diff --git a/src/lib.rs b/src/lib.rs index a284a81..6fb5eea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ use std::{sync, time}; pub mod formats; pub mod types; +pub mod router; pub mod handlers; pub mod syntax; pub mod dev; diff --git a/src/main.rs b/src/main.rs index a0e128a..d690bf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ use std::{backtrace, io, panic}; -use axum::{routing::get, Router}; - -use en::{ONSET, handlers, syntax, dev, formats::Format}; +use en::{ONSET, syntax, dev}; #[tokio::main] async fn main() -> io::Result<()> { @@ -27,41 +25,7 @@ async fn main() -> io::Result<()> { } })); - let app = Router::new() - .route( - "/", - get(|| handlers::navigation::nexus("index.html")) - .post(handlers::navigation::search), - ) - .route( - "/graph/toml", - get(|| handlers::fixed::serial(&Format::Toml)), - ) - .route( - "/graph/json", - get(|| handlers::fixed::serial(&Format::Json)), - ) - .route( - "/static/style.css", - get(|| handlers::fixed::file("./static/style.css", "text/css")), - ) - .route( - "/static/favicon.svg", - get(|| { - handlers::fixed::file("./static/favicon.svg", "image/svg+xml") - }), - ) - .route( - "/node/{node_id}", - get(handlers::graph::node).post(handlers::graph::node), - ) - .route("/tree", get(|| handlers::navigation::nexus("tree.html"))) - .route("/about", get(|| handlers::template::fixed("about.html"))) - .route( - "/acknowledgments", - get(|| handlers::template::fixed("acknowledgments.html")), - ) - .fallback(handlers::error::not_found); + let app = en::router::new(); let listener = tokio::net::TcpListener::bind(&address).await.map_err(|e| { diff --git a/src/router.rs b/src/router.rs new file mode 100644 index 0000000..4357b1d --- /dev/null +++ b/src/router.rs @@ -0,0 +1,41 @@ +use axum::{routing::get, Router}; + +use crate::{handlers, formats::Format}; + +pub fn new() -> Router { + Router::new() + .route( + "/", + get(|| handlers::navigation::nexus("index.html")) + .post(handlers::navigation::search), + ) + .route( + "/graph/toml", + get(|| handlers::fixed::serial(&Format::Toml)), + ) + .route( + "/graph/json", + get(|| handlers::fixed::serial(&Format::Json)), + ) + .route( + "/static/style.css", + get(|| handlers::fixed::file("./static/style.css", "text/css")), + ) + .route( + "/static/favicon.svg", + get(|| { + handlers::fixed::file("./static/favicon.svg", "image/svg+xml") + }), + ) + .route( + "/node/{node_id}", + get(handlers::graph::node).post(handlers::graph::node), + ) + .route("/tree", get(|| handlers::navigation::nexus("tree.html"))) + .route("/about", get(|| handlers::template::fixed("about.html"))) + .route( + "/acknowledgments", + get(|| handlers::template::fixed("acknowledgments.html")), + ) + .fallback(handlers::error::not_found) +}