read values from managed state

This commit is contained in:
glyph 2022-01-18 17:00:53 +02:00
parent bfb53747db
commit 43344566de
3 changed files with 11 additions and 10 deletions

View File

@ -14,8 +14,8 @@ use crate::routes::{
/// catchers. This gives us everything we need to run PeachPub and excludes
/// settings and status routes related to networking and the device (memory,
/// hard disk, CPU etc.).
pub fn mount_peachpub_routes() -> Rocket<Build> {
rocket::build()
pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
rocket
.mount(
"/",
routes![
@ -66,8 +66,8 @@ pub fn mount_peachpub_routes() -> Rocket<Build> {
/// Create a Rocket instance with PeachPub routes, fileserver and catchers by
/// calling `mount_peachpub_routes()` and then mount all additional routes
/// required to run a complete PeachCloud build.
pub fn mount_peachcloud_routes() -> Rocket<Build> {
mount_peachpub_routes()
pub fn mount_peachcloud_routes(rocket: Rocket<Build>) -> Rocket<Build> {
mount_peachpub_routes(rocket)
.mount(
"/settings/network",
routes![

View File

@ -1,19 +1,20 @@
use rocket::{get, request::FlashMessage};
use rocket::{get, request::FlashMessage, State};
use rocket_dyn_templates::{tera::Context, Template};
use crate::routes::authentication::Authenticated;
use crate::STANDALONE_MODE;
use crate::RocketConfig;
// HELPERS AND ROUTES FOR / (HOME PAGE)
#[get("/")]
pub fn home(_auth: Authenticated) -> Template {
pub fn home(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
let mut context = Context::new();
context.insert("flash_name", &None::<()>);
context.insert("flash_msg", &None::<()>);
context.insert("title", &None::<()>);
// pass in mode so we can define appropriate urls in template
context.insert("standalone_mode", &*STANDALONE_MODE);
// pass in mode from managed state so we can define appropriate urls in template
context.insert("standalone_mode", &config.standalone_mode);
Template::render("home", &context.into_json())
}

View File

@ -1,4 +1,4 @@
use rocket::{get, request::FlashMessage};
use rocket::get;
use rocket_dyn_templates::{tera::Context, Template};
use crate::routes::authentication::Authenticated;