diff --git a/src/lib/web/mavlink_endpoints.rs b/src/lib/web/mavlink_endpoints.rs index 2a992bf..f7eb0b6 100644 --- a/src/lib/web/mavlink_endpoints.rs +++ b/src/lib/web/mavlink_endpoints.rs @@ -8,7 +8,8 @@ use axum::{ }, http::StatusCode, response::{IntoResponse, Response}, - Json, + routing::{get, post}, + Json, Router, }; use futures::{sink::SinkExt, stream::StreamExt}; @@ -18,6 +19,20 @@ use uuid::Uuid; use crate::web::{broadcast_message_websockets, AppState}; +pub fn router() -> Router { + Router::new() + .route("/ws", get(websocket_handler)) + // We are matching all possible keys for the user + .route("/mavlink", get(mavlink)) + .route("/mavlink", post(post_mavlink)) + .route("/mavlink/", get(mavlink)) + .route("/mavlink/*path", get(mavlink)) + .route( + "/mavlink/message_id_from_name/*name", + get(message_id_from_name), + ) +} + pub async fn mavlink(path: Option>) -> impl IntoResponse { let path = match path { Some(path) => path.0.to_string(), diff --git a/src/lib/web/mod.rs b/src/lib/web/mod.rs index 7ba349a..c925544 100644 --- a/src/lib/web/mod.rs +++ b/src/lib/web/mod.rs @@ -14,7 +14,7 @@ use axum::{ }, http::StatusCode, response::Response, - routing::{get, post}, + routing::get, Router, }; use futures::{sink::SinkExt, stream::StreamExt}; @@ -49,16 +49,7 @@ fn default_router(state: AppState) -> Router { "/stats/messages/ws", get(hub_messages_stats_websocket_handler), ) - .route("/rest/ws", get(mavlink_endpoints::websocket_handler)) - // We are matching all possible keys for the user - .route("/rest/mavlink", get(mavlink_endpoints::mavlink)) - .route("/rest/mavlink", post(mavlink_endpoints::post_mavlink)) - .route("/rest/mavlink/", get(mavlink_endpoints::mavlink)) - .route("/rest/mavlink/*path", get(mavlink_endpoints::mavlink)) - .route( - "/rest/mavlink/message_id_from_name/*name", - get(mavlink_endpoints::message_id_from_name), - ) + .nest("/rest/", mavlink_endpoints::router()) .fallback(get(|| async { (StatusCode::NOT_FOUND, "Not found :(") })) .with_state(state) }