deduplicate mounting of routes

This commit is contained in:
2022-01-18 12:50:06 +02:00
parent 44b68a8b71
commit 792779f60f
2 changed files with 13 additions and 66 deletions

View File

@ -55,9 +55,9 @@ static AP_IFACE: &str = "ap0";
pub fn init_rocket() -> Rocket<Build> { pub fn init_rocket() -> Rocket<Build> {
info!("Initializing Rocket"); info!("Initializing Rocket");
if *STANDALONE_MODE { if *STANDALONE_MODE {
router::build_minimal_rocket() router::mount_peachpub_routes()
} else { } else {
router::build_complete_rocket() router::mount_peachcloud_routes()
} }
} }

View File

@ -7,15 +7,15 @@ use crate::routes::{
index::*, index::*,
scuttlebutt::*, scuttlebutt::*,
settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*}, settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*},
status::{device::*, network::*}, status::{device::*, network::*, scuttlebutt::*},
}; };
/// Create minimal rocket instance and mount routes. This excludes settings /// Create a Rocket instance and mount PeachPub routes, fileserver and
/// and status routes related to networking and the device (memory, /// 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.). /// hard disk, CPU etc.).
pub fn build_minimal_rocket() -> Rocket<Build> { pub fn mount_peachpub_routes() -> Rocket<Build> {
rocket::build() rocket::build()
// GENERAL HTML ROUTES
.mount( .mount(
"/", "/",
routes![ routes![
@ -30,7 +30,6 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
settings_menu, settings_menu,
], ],
) )
// ADMIN SETTINGS HTML ROUTES
.mount( .mount(
"/settings/admin", "/settings/admin",
routes![ routes![
@ -47,12 +46,10 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
send_password_reset_post, send_password_reset_post,
], ],
) )
// SCUTTLEBUTT SETTINGS HTML ROUTES
.mount( .mount(
"/settings/scuttlebutt", "/settings/scuttlebutt",
routes![ssb_settings_menu, configure_sbot], routes![ssb_settings_menu, configure_sbot],
) )
// SCUTTLEBUTT SOCIAL HTML ROUTES
.mount( .mount(
"/scuttlebutt", "/scuttlebutt",
routes![ routes![
@ -60,50 +57,17 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
block, publish, block, publish,
], ],
) )
// STATUS HTML ROUTES .mount("/status", routes![scuttlebutt_status])
// TODO: replace this with a route for `scuttlebutt_status`
.mount("/status", routes![device_status, network_status])
.mount("/", FileServer::from("static")) .mount("/", FileServer::from("static"))
.register("/", catchers![not_found, internal_error, forbidden]) .register("/", catchers![not_found, internal_error, forbidden])
.attach(Template::fairing()) .attach(Template::fairing())
} }
/// Create complete rocket instance and mount all routes. /// Create a Rocket instance with PeachPub routes, fileserver and catchers by
pub fn build_complete_rocket() -> Rocket<Build> { /// calling `mount_peachpub_routes()` and then mount all additional routes
rocket::build() /// required to run a complete PeachCloud build.
// GENERAL HTML ROUTES pub fn mount_peachcloud_routes() -> Rocket<Build> {
.mount( mount_peachpub_routes()
"/",
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
.mount( .mount(
"/settings/network", "/settings/network",
routes![ routes![
@ -127,22 +91,5 @@ pub fn build_complete_rocket() -> Rocket<Build> {
wifi_usage_reset, 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("/status", routes![device_status, network_status])
.mount("/", FileServer::from("static"))
.register("/", catchers![not_found, internal_error, forbidden])
.attach(Template::fairing())
} }