| 
									
										
										
										
											2023-04-08 12:40:57 -05:00
										 |  |  | //! # Rust Letter Backend
 | 
					
						
							| 
									
										
										
										
											2023-04-09 12:34:40 -05:00
										 |  |  | //!
 | 
					
						
							| 
									
										
										
										
											2023-04-08 12:40:57 -05:00
										 |  |  | //! `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;
 | 
					
						
							| 
									
										
										
										
											2023-04-09 12:34:40 -05:00
										 |  |  |     use rocket::{Build, Rocket};
 | 
					
						
							|  |  |  |     use rocket_dyn_templates::{context, Template};
 | 
					
						
							|  |  |  |     use void_fe::void_app::{self, PoemRequest, VirtualDom};
 | 
					
						
							| 
									
										
										
										
											2023-04-08 12:40:57 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     #[get("/")]
 | 
					
						
							|  |  |  |     async fn index() -> Template {
 | 
					
						
							| 
									
										
										
										
											2023-04-08 20:47:51 -05:00
										 |  |  |         let mut vdom = VirtualDom::new(void_app::HomePage);
 | 
					
						
							| 
									
										
										
										
											2023-04-08 12:40:57 -05:00
										 |  |  |         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
 | 
					
						
							|  |  |  |             },
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2023-04-07 07:41:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 12:34:40 -05:00
										 |  |  |     #[get("/poem/<entry>")]
 | 
					
						
							|  |  |  |     async fn poem(entry: &str) -> Template {
 | 
					
						
							|  |  |  |         let mut vdom = VirtualDom::new_with_props(
 | 
					
						
							|  |  |  |             void_app::PoemPage,
 | 
					
						
							|  |  |  |             PoemRequest {
 | 
					
						
							|  |  |  |                 slug: entry.to_string(),
 | 
					
						
							|  |  |  |             },
 | 
					
						
							|  |  |  |         );
 | 
					
						
							|  |  |  |         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
 | 
					
						
							|  |  |  |             },
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 12:40:57 -05:00
										 |  |  |     /// 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"))
 | 
					
						
							| 
									
										
										
										
											2023-04-09 12:34:40 -05:00
										 |  |  |             .mount("/", routes![index, poem])
 | 
					
						
							|  |  |  |             .attach(Template::fairing())
 | 
					
						
							| 
									
										
										
										
											2023-04-07 07:41:48 -05:00
										 |  |  |     }
 | 
					
						
							|  |  |  | }
 |