why not add another route for wrapping the html output in a valid document. for fun

This commit is contained in:
Erin 2024-04-15 03:38:29 -04:00
parent f181ecce95
commit f65d564c9c
Signed by: erin
SSH key fingerprint: SHA256:clvLPaxKthBet+VUQTKQdDkjaqg2/KnYHQaPASp5pFE

View file

@ -74,6 +74,22 @@ async fn html(
Ok(content::RawHtml(html)) Ok(content::RawHtml(html))
} }
// this will probably never be used but it was a neat simple thing for me to
// implement to show that i know what im doing with this language. im good at
// this programming stuff i promise
#[rocket::get("/html_full?<page>")]
async fn html_full(
page: &str,
pool: &rocket::State<SqlitePool>,
) -> Result<content::RawHtml<String>, String> {
html(page, pool).await.map(|html| {
content::RawHtml(format!(
"<!DOCTYPE html><html><body>{}</body></html>",
html.0
))
})
}
#[rocket::get("/add?<page>&<name>&<content>")] #[rocket::get("/add?<page>&<name>&<content>")]
async fn add( async fn add(
page: &str, page: &str,
@ -102,5 +118,5 @@ async fn rocket() -> _ {
.expect("Failed to connect to database"); .expect("Failed to connect to database");
rocket::build() rocket::build()
.manage(pool) .manage(pool)
.mount("/", rocket::routes![txt, html, add]) .mount("/", rocket::routes![txt, html, html_full, add])
} }