Skip to content

Commit

Permalink
feat(rumqttd): console endpoint /config prints router config (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
swanandx authored Oct 9, 2023
1 parent 0f8cc40 commit b59e018
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions rumqttd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- Console endpoint /config prints Router Config instead of returning console settings

### Deprecated

Expand Down
14 changes: 10 additions & 4 deletions rumqttd/src/link/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::local::LinkBuilder;
use crate::router::{Event, Print};
use crate::{ConnectionId, ConsoleSettings};
use axum::extract::{Path, State};
use axum::response::{IntoResponse, Redirect, Response};
use axum::response::{IntoResponse, Response};
use axum::routing::post;
use axum::Json;
use axum::{routing::get, Router};
Expand Down Expand Up @@ -61,12 +61,18 @@ pub async fn start(console: Arc<ConsoleLink>) {
.unwrap();
}

async fn root() -> impl IntoResponse {
Redirect::to("/config")
async fn root(State(console): State<Arc<ConsoleLink>>) -> impl IntoResponse {
Json(console.config.clone())
}

async fn config(State(console): State<Arc<ConsoleLink>>) -> impl IntoResponse {
Json(console.config.clone())
let event = Event::PrintStatus(Print::Config);
let message = (console.connection_id, event);
if console.router_tx.send(message).is_err() {
return Response::builder().status(404).body("".to_owned()).unwrap();
}

Response::new("OK".to_owned())
}

async fn router(State(console): State<Arc<ConsoleLink>>) -> impl IntoResponse {
Expand Down

0 comments on commit b59e018

Please sign in to comment.