Skip to content

Commit

Permalink
web: Move mavlink endpoints to service
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Nov 13, 2024
1 parent 9ea2477 commit f1175e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 16 additions & 1 deletion src/lib/web/mavlink_endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use axum::{
},
http::StatusCode,
response::{IntoResponse, Response},
Json,
routing::{get, post},
Json, Router,
};

use futures::{sink::SinkExt, stream::StreamExt};
Expand All @@ -18,6 +19,20 @@ use uuid::Uuid;

use crate::web::{broadcast_message_websockets, AppState};

pub fn router() -> Router<AppState> {
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<Path<String>>) -> impl IntoResponse {
let path = match path {
Some(path) => path.0.to_string(),
Expand Down
13 changes: 2 additions & 11 deletions src/lib/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use axum::{
},
http::StatusCode,
response::Response,
routing::{get, post},
routing::get,
Router,
};
use futures::{sink::SinkExt, stream::StreamExt};
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f1175e8

Please sign in to comment.