From 792779f60f5f71beed9808d0eefde64432f70560 Mon Sep 17 00:00:00 2001 From: glyph Date: Tue, 18 Jan 2022 12:50:06 +0200 Subject: [PATCH] deduplicate mounting of routes --- peach-web/src/main.rs | 4 +-- peach-web/src/router.rs | 75 ++++++----------------------------------- 2 files changed, 13 insertions(+), 66 deletions(-) diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index 56c8f75..ded1686 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -55,9 +55,9 @@ static AP_IFACE: &str = "ap0"; pub fn init_rocket() -> Rocket { info!("Initializing Rocket"); if *STANDALONE_MODE { - router::build_minimal_rocket() + router::mount_peachpub_routes() } else { - router::build_complete_rocket() + router::mount_peachcloud_routes() } } diff --git a/peach-web/src/router.rs b/peach-web/src/router.rs index 51e34c5..341d9aa 100644 --- a/peach-web/src/router.rs +++ b/peach-web/src/router.rs @@ -7,15 +7,15 @@ use crate::routes::{ index::*, scuttlebutt::*, settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*}, - status::{device::*, network::*}, + status::{device::*, network::*, scuttlebutt::*}, }; -/// Create minimal rocket instance and mount routes. This excludes settings -/// and status routes related to networking and the device (memory, +/// Create a Rocket instance and mount PeachPub routes, fileserver and +/// 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 build_minimal_rocket() -> Rocket { +pub fn mount_peachpub_routes() -> Rocket { rocket::build() - // GENERAL HTML ROUTES .mount( "/", routes![ @@ -30,7 +30,6 @@ pub fn build_minimal_rocket() -> Rocket { settings_menu, ], ) - // ADMIN SETTINGS HTML ROUTES .mount( "/settings/admin", routes![ @@ -47,12 +46,10 @@ pub fn build_minimal_rocket() -> Rocket { send_password_reset_post, ], ) - // SCUTTLEBUTT SETTINGS HTML ROUTES .mount( "/settings/scuttlebutt", routes![ssb_settings_menu, configure_sbot], ) - // SCUTTLEBUTT SOCIAL HTML ROUTES .mount( "/scuttlebutt", routes![ @@ -60,50 +57,17 @@ pub fn build_minimal_rocket() -> Rocket { block, publish, ], ) - // STATUS HTML ROUTES - // TODO: replace this with a route for `scuttlebutt_status` - .mount("/status", routes![device_status, network_status]) + .mount("/status", routes![scuttlebutt_status]) .mount("/", FileServer::from("static")) .register("/", catchers![not_found, internal_error, forbidden]) .attach(Template::fairing()) } -/// Create complete rocket instance and mount all routes. -pub fn build_complete_rocket() -> Rocket { - rocket::build() - // GENERAL HTML ROUTES - .mount( - "/", - routes![ - help, - home, - login, - login_post, - logout, - reboot_cmd, - shutdown_cmd, - power_menu, - settings_menu, - ], - ) - // ADMIN SETTINGS HTML ROUTES - .mount( - "/settings/admin", - routes![ - admin_menu, - configure_admin, - add_admin, - add_admin_post, - delete_admin_post, - change_password, - change_password_post, - reset_password, - reset_password_post, - forgot_password_page, - send_password_reset_post, - ], - ) - // NETWORK SETTINGS HTML ROUTES +/// 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 { + mount_peachpub_routes() .mount( "/settings/network", routes![ @@ -127,22 +91,5 @@ pub fn build_complete_rocket() -> Rocket { wifi_usage_reset, ], ) - // SCUTTLEBUTT SETTINGS HTML ROUTES - .mount( - "/settings/scuttlebutt", - routes![ssb_settings_menu, configure_sbot], - ) - // SCUTTLEBUTT SOCIAL HTML ROUTES - .mount( - "/scuttlebutt", - routes![ - peers, friends, follows, followers, blocks, profile, private, follow, unfollow, - block, publish, - ], - ) - // STATUS HTML ROUTES .mount("/status", routes![device_status, network_status]) - .mount("/", FileServer::from("static")) - .register("/", catchers![not_found, internal_error, forbidden]) - .attach(Template::fairing()) }