deduplicate mounting of routes

This commit is contained in:
glyph 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> {
info!("Initializing Rocket");
if *STANDALONE_MODE {
router::build_minimal_rocket()
router::mount_peachpub_routes()
} else {
router::build_complete_rocket()
router::mount_peachcloud_routes()
}
}

View File

@ -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<Build> {
pub fn mount_peachpub_routes() -> Rocket<Build> {
rocket::build()
// GENERAL HTML ROUTES
.mount(
"/",
routes![
@ -30,7 +30,6 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
settings_menu,
],
)
// ADMIN SETTINGS HTML ROUTES
.mount(
"/settings/admin",
routes![
@ -47,12 +46,10 @@ pub fn build_minimal_rocket() -> Rocket<Build> {
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<Build> {
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<Build> {
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<Build> {
mount_peachpub_routes()
.mount(
"/settings/network",
routes![
@ -127,22 +91,5 @@ pub fn build_complete_rocket() -> Rocket<Build> {
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())
}