mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-23 22:09:22 +00:00
41 lines
999 B
Rust
41 lines
999 B
Rust
|
use std::error::Error;
|
||
|
|
||
|
use crate::controllers::routes::Method::GET;
|
||
|
use crate::controllers::server_controller;
|
||
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||
|
|
||
|
/// Project routes
|
||
|
///
|
||
|
/// @author Pierre Hubert
|
||
|
|
||
|
#[derive(PartialEq)]
|
||
|
pub enum Method {
|
||
|
GET,
|
||
|
POST,
|
||
|
}
|
||
|
|
||
|
/// Define types
|
||
|
pub type RequestResult = Result<(), Box<dyn Error>>;
|
||
|
pub type RequestProcess = Box<dyn Fn(&mut HttpRequestHandler) -> RequestResult>;
|
||
|
|
||
|
pub struct Route {
|
||
|
/// The Verb used for the request
|
||
|
pub method: Method,
|
||
|
|
||
|
/// The URI of the request, with the leading "/"
|
||
|
pub uri: &'static str,
|
||
|
|
||
|
/// If set to true, unauthenticated requests will be rejected
|
||
|
pub need_login: bool,
|
||
|
|
||
|
/// The function called to process a request
|
||
|
pub func: RequestProcess,
|
||
|
}
|
||
|
|
||
|
/// Get the list of routes available
|
||
|
pub fn get_routes() -> Vec<Route> {
|
||
|
vec![
|
||
|
// Server meta routes
|
||
|
Route { method: GET, uri: "/", need_login: false, func: Box::new(server_controller::main_index) }
|
||
|
]
|
||
|
}
|