Files
build-joeac/src/main.rs
T
2026-06-08 09:08:13 +01:00

39 lines
1.1 KiB
Rust

use std::path::PathBuf;
use dirs::config_dir;
#[macro_use] extern crate rocket;
mod routes;
use anyhow::Result;
use routes::read_routes;
use rocket::{State, http::Status};
const BIN_NAME: &str = "shapi";
#[launch]
fn rocket() -> _ {
let routes_path: PathBuf = config_dir().unwrap().join(BIN_NAME).join("routes");
let routes = read_routes(&routes_path).expect("Failed to read routes config");
rocket::build().manage(routes).mount("/", routes![index])
}
#[get("/<req_path..>")]
fn index(req_path: PathBuf, routes: &State<Vec<String>>) -> (Status, String) {
match req_path.to_str().map(String::from) {
None => (Status::BadRequest, format!("Failed to convert request path to unicode: {:?}", req_path)),
Some(req_path) => match routes.iter().find(|&route| req_path.eq(route)) {
None => (Status::NotFound, format!("Route not configured: {req_path}")),
Some(route) => match execute_route(route) {
Ok(_) => todo!(),
Err(_) => todo!(),
},
}
}
}
fn execute_route(route: &str) -> Result<()> {
todo!();
}