Skip to content

console endpoint /config prints router config #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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