
//! # Rust Letter Backend
//! 
//! `rust_letter_be` handles the backend execution using Rocket.

#[macro_use]
extern crate rocket;

/// A module that handles the backend for the site.
pub mod web_app_backend {

    use rocket::fs::FileServer;
    use rocket::{Rocket, Build};
    use rocket_dyn_templates::{Template, context};
    use void_fe::void_app::{self, VirtualDom};

    #[get("/")]
    async fn index() -> Template {
        let mut vdom = VirtualDom::new(void_app::App);
        let _ = vdom.rebuild();
        let output = dioxus_ssr::render(&vdom);
        Template::render(
            "index",
            context! {
                app_title: "A Letter to the Void",
                style_include: "<link href=/styles/tailwind.min.css rel=stylesheet />",
                test: &output
            },
        )
    }

    /// This runs `rocket::build()` with the needed mounts and routes.
    pub async fn build_rocket() -> Rocket<Build> {
        rocket::build()
            .mount("/images", FileServer::from("public/images"))
            .mount("/styles", FileServer::from("public/styles"))
            .mount("/fonts", FileServer::from("public/fonts"))
            .mount("/", routes![index]).attach(Template::fairing())
    }
}
