dioxus-letter-werefox-cafe/rust-letter-be/src/lib.rs

41 lines
1.2 KiB
Rust

//! # 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 rust_letter_fe::web_app::{self, VirtualDom};
#[get("/")]
async fn index() -> Template {
let mut vdom = VirtualDom::new(web_app::App);
let _ = vdom.rebuild();
let output = dioxus_ssr::render(&vdom);
Template::render(
"index",
context! {
app_title: "A Letter For You!",
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())
}
}