peach-workspace/peach-web/src/router.rs

250 lines
7.6 KiB
Rust
Raw Normal View History

2022-03-20 15:17:17 +00:00
use rouille::{router, Request, Response};
use crate::{routes, utils::flash::FlashResponse};
/// Define the PeachPub router.
///
/// Takes an incoming request and matches on the defined routes,
/// returning either a template or a redirect.
///
/// Excludes settings and status routes related to networking and the device
/// (memory, hard disk, CPU etc.).
pub fn mount_peachpub_routes(request: &Request) -> Response {
router!(request,
(GET) (/) => {
Response::html(routes::home::build_template())
},
(GET) (/auth/change) => {
// build the html template
Response::html(routes::authentication::change::build_template(request))
// reset the flash msg cookies in the response object
.reset_flash()
},
(POST) (/auth/change) => {
routes::authentication::change::handle_form(request)
},
(GET) (/auth/login) => {
Response::html(routes::authentication::login::build_template(request))
.reset_flash()
},
(POST) (/auth/login) => {
routes::authentication::login::handle_form(request)
},
(GET) (/auth/logout) => {
routes::authentication::logout::deauthenticate()
},
(GET) (/auth/reset) => {
Response::html(routes::authentication::reset::build_template(request))
.reset_flash()
},
(POST) (/auth/reset) => {
routes::authentication::reset::handle_form(request)
},
(GET) (/guide) => {
Response::html(routes::guide::build_template())
},
(GET) (/settings) => {
Response::html(routes::settings::menu::build_template())
},
(GET) (/settings/scuttlebutt) => {
Response::html(routes::settings::scuttlebutt::menu::build_template(request))
.reset_flash()
},
(GET) (/settings/scuttlebutt/restart) => {
routes::settings::scuttlebutt::restart::restart_sbot()
},
(GET) (/settings/scuttlebutt/start) => {
routes::settings::scuttlebutt::start::start_sbot()
},
(GET) (/settings/scuttlebutt/stop) => {
routes::settings::scuttlebutt::stop::stop_sbot()
},
(GET) (/settings/scuttlebutt/configure) => {
Response::html(routes::settings::scuttlebutt::configure::build_template())
},
(GET) (/settings/admin) => {
Response::html(routes::settings::admin::menu::build_template())
},
(POST) (/settings/admin/add) => {
routes::settings::admin::add::handle_form(request)
},
(GET) (/settings/admin/configure) => {
Response::html(routes::settings::admin::configure::build_template(request))
.reset_flash()
},
(POST) (/settings/admin/delete) => {
routes::settings::admin::delete::handle_form(request)
},
(GET) (/scuttlebutt/blocks) => {
Response::html(routes::scuttlebutt::blocks::build_template())
},
(GET) (/scuttlebutt/follows) => {
Response::html(routes::scuttlebutt::follows::build_template())
},
(GET) (/scuttlebutt/friends) => {
Response::html(routes::scuttlebutt::friends::build_template())
},
2022-03-20 15:17:17 +00:00
(GET) (/scuttlebutt/peers) => {
Response::html(routes::scuttlebutt::peers::build_template())
},
(GET) (/status/scuttlebutt) => {
Response::html(routes::status::scuttlebutt::build_template())
},
// The code block is called if none of the other blocks matches the request.
// We return an empty response with a 404 status code.
_ => Response::empty_404()
)
}
/*
use rocket::{catchers, fs::FileServer, routes, Build, Rocket};
use rocket_dyn_templates::Template;
use crate::{
routes::{
authentication::*,
catchers::*,
index::*,
scuttlebutt::*,
settings::{admin::*, dns::*, menu::*, network::*, scuttlebutt::*, theme::*},
status::{device::*, network::*, scuttlebutt::*},
},
utils,
};
2022-01-18 10:50:06 +00:00
/// 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.).
2022-01-18 15:00:53 +00:00
pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
// set the `.ssb-go` path in order to mount the blob fileserver
let ssb_path = utils::get_go_ssb_path().expect("define ssb-go dir path");
let blobstore = format!("{}/blobs/sha256", ssb_path);
2022-01-18 15:00:53 +00:00
rocket
.mount(
"/",
routes![
2022-03-07 09:35:19 +00:00
guide,
home,
login,
login_post,
logout,
settings_menu,
set_theme,
],
)
.mount(
"/settings/admin",
routes![
admin_menu,
configure_admin,
add_admin_post,
delete_admin_post,
change_password,
change_password_post,
reset_password,
reset_password_post,
forgot_password_page,
send_password_reset_post,
],
)
2022-01-17 13:20:08 +00:00
.mount(
"/settings/scuttlebutt",
routes![
ssb_settings_menu,
configure_sbot,
2022-02-02 12:14:12 +00:00
configure_sbot_default,
configure_sbot_post,
restart_sbot,
start_sbot,
stop_sbot
],
2022-01-17 13:20:08 +00:00
)
.mount(
"/scuttlebutt",
routes![
2022-02-23 08:21:58 +00:00
invites,
create_invite,
peers,
search,
search_post,
friends,
follows,
blocks,
profile,
update_profile,
update_profile_post,
private,
2022-03-02 09:57:10 +00:00
private_post,
follow,
unfollow,
block,
unblock,
publish,
],
)
2022-01-18 10:50:06 +00:00
.mount("/status", routes![scuttlebutt_status])
.mount("/", FileServer::from("static"))
.mount("/blob", FileServer::from(blobstore).rank(-1))
.register("/", catchers![not_found, internal_error, forbidden])
.attach(Template::fairing())
}
2022-01-18 10:50:06 +00:00
/// 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.
2022-01-18 15:00:53 +00:00
pub fn mount_peachcloud_routes(rocket: Rocket<Build>) -> Rocket<Build> {
mount_peachpub_routes(rocket)
.mount("/", routes![reboot_cmd, shutdown_cmd, power_menu,])
.mount(
"/settings/network",
routes![
add_credentials,
connect_wifi,
configure_dns,
configure_dns_post,
disconnect_wifi,
deploy_ap,
deploy_client,
forget_wifi,
network_home,
add_ssid,
add_wifi,
network_detail,
wifi_list,
wifi_password,
wifi_set_password,
wifi_usage,
wifi_usage_alerts,
wifi_usage_reset,
],
)
.mount("/status", routes![device_status, network_status])
}
2022-03-20 15:17:17 +00:00
*/