FeDirect/src/main.rs
CenTdemeern1 c856ab9900 Redo safety checks for instance_info
Using the `ip` feature, and some clever use of `Url::set_host` and `Url::host_str`
2025-01-29 22:13:14 +01:00

59 lines
1.4 KiB
Rust

#![feature(ip)]
#[macro_use]
extern crate rocket;
use known_software::KnownInstanceSoftware;
use rocket::{
fs::{FileServer, NamedFile},
http::ContentType,
};
use std::path::PathBuf;
mod api;
mod known_software;
#[get("/known-software.json")]
async fn known_software_json() -> Option<NamedFile> {
NamedFile::open("known-software.json").await.ok()
}
#[get("/<instance>/<route..>", rank = 1)]
async fn route_for_known_instance_software(
instance: KnownInstanceSoftware<'_>,
route: PathBuf,
) -> Option<NamedFile> {
NamedFile::open("static/crossroad.html").await.ok()
}
#[get("/")]
async fn configure_page() -> Option<NamedFile> {
NamedFile::open("static/config.html").await.ok()
}
#[get("/<instance>/<route..>", rank = 2)]
fn route_for_unknown_instance_software(instance: &str, route: PathBuf) -> (ContentType, String) {
(
ContentType::HTML,
format!(
"Hello from <code>{}</code>! The software <code>{}</code> is unknown.",
route.display(),
instance
),
)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/static", FileServer::from("static").rank(0))
.mount("/api", api::get_routes())
.mount(
"/",
routes![
known_software_json,
route_for_known_instance_software,
route_for_unknown_instance_software,
configure_page
],
)
}