reorder routes

master
Edward Shen 2019-12-31 23:00:54 -05:00
parent b8be3d8d53
commit 1d7d547475
Signed by: edward
GPG Key ID: F350507060ED6C90
2 changed files with 50 additions and 39 deletions

View File

@ -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();
}
}

View File

@ -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::<Handlebars>()
.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::<Handlebars>()
.unwrap()
.render(
"opensearch",
&template_args::hostname(data.public_address.clone()),
)
.unwrap(),
)
}
#[get("/ls")]
pub async fn list(
data: Data<Arc<RwLock<State>>>,
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::<Handlebars>()
.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<Vec<u8>, 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::<Handlebars>()
.unwrap()
.render(
"opensearch",
&template_args::hostname(data.public_address.clone()),
)
.unwrap(),
)
}
#[cfg(test)]
mod route {
use super::*;