#[derive(Debug, Clone, PartialEq)]
pub enum Route {
Health,
GetConfig,
UpdateConfig,
Execute,
Metrics,
WebSocket,
Login,
Logout,
AuthStatus,
ServeIndex,
ServeStatic(String),
NotFound,
}
pub struct Router;
impl Router {
pub fn route(method: &str, path: &str) -> Route {
match (method, path) {
("GET", "/v1/health") => Route::Health,
("GET", "/v1/config") => Route::GetConfig,
("PUT", "/v1/config") => Route::UpdateConfig,
("POST", "/v1/execute") => Route::Execute,
("GET", "/v1/metrics") => Route::Metrics,
("GET", "/v1/ws") => Route::WebSocket,
("POST", "/v1/auth/login") => Route::Login,
("POST", "/v1/auth/logout") => Route::Logout,
("GET", "/v1/auth/status") => Route::AuthStatus,
("GET", "/") => Route::ServeIndex,
("GET", p) if p.starts_with("/assets/") => Route::ServeStatic(p.to_string()),
("GET", p) if !p.starts_with("/v1/") => Route::ServeIndex,
_ => Route::NotFound,
}
}
}