diff --git a/src/main.rs b/src/main.rs index 7de3bf8..5c858cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -287,3 +287,17 @@ mod cache_routes { ); } } + +#[cfg(test)] +mod compile_templates { + use super::compile_templates; + + /// Successful compilation of the binary guarantees that the templates will be + /// present to be registered to. Thus, we only really need to see that + /// compilation of the templates don't panic, which is just making sure that + /// the function can be successfully called. + #[test] + fn templates_compile() { + let _ = compile_templates(); + } +} diff --git a/src/routes.rs b/src/routes.rs index 687a003..b3e4126 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -91,11 +91,43 @@ impl std::fmt::Display for Route { } } +#[get("/")] +pub async fn index(data: StateData, req: HttpRequest) -> impl Responder { + let data = data.read().unwrap(); + HttpResponse::Ok().body( + req + .app_data::() + .unwrap() + .render( + "index", + &template_args::hostname(data.public_address.clone()), + ) + .unwrap(), + ) +} + +#[get("/bunbunsearch.xml")] +pub async fn opensearch(data: StateData, req: HttpRequest) -> impl Responder { + let data = data.read().unwrap(); + HttpResponse::Ok() + .header( + header::CONTENT_TYPE, + "application/opensearchdescription+xml", + ) + .body( + req + .app_data::() + .unwrap() + .render( + "opensearch", + &template_args::hostname(data.public_address.clone()), + ) + .unwrap(), + ) +} + #[get("/ls")] -pub async fn list( - data: Data>>, - req: HttpRequest, -) -> impl Responder { +pub async fn list(data: StateData, req: HttpRequest) -> impl Responder { let data = data.read().unwrap(); HttpResponse::Ok().body( req @@ -206,21 +238,6 @@ fn resolve_hop<'a>( } } -#[get("/")] -pub async fn index(data: StateData, req: HttpRequest) -> impl Responder { - let data = data.read().unwrap(); - HttpResponse::Ok().body( - req - .app_data::() - .unwrap() - .render( - "index", - &template_args::hostname(data.public_address.clone()), - ) - .unwrap(), - ) -} - /// Runs the executable with the user's input as a single argument. Returns Ok /// so long as the executable was successfully executed. Returns an Error if the /// file doesn't exist or bunbun did not have permission to read and execute the @@ -240,26 +257,6 @@ fn resolve_path(path: PathBuf, args: &str) -> Result, BunBunError> { } } -#[get("/bunbunsearch.xml")] -pub async fn opensearch(data: StateData, req: HttpRequest) -> impl Responder { - let data = data.read().unwrap(); - HttpResponse::Ok() - .header( - header::CONTENT_TYPE, - "application/opensearchdescription+xml", - ) - .body( - req - .app_data::() - .unwrap() - .render( - "opensearch", - &template_args::hostname(data.public_address.clone()), - ) - .unwrap(), - ) -} - #[cfg(test)] mod route { use super::*;