httpd: Add socketAddress to `/node` endpoint
This allows us in the web client to show and let user copy the node id together with the correct port number Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
parent
d0fdd0b6a3
commit
f418b5268c
|
|
@ -1,6 +1,7 @@
|
|||
pub mod auth;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -38,6 +39,7 @@ pub struct Context {
|
|||
profile: Arc<Profile>,
|
||||
sessions: Arc<RwLock<HashMap<SessionId, auth::Session>>>,
|
||||
cache: Option<Cache>,
|
||||
address: SocketAddr,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
|
|
@ -46,6 +48,7 @@ impl Context {
|
|||
profile,
|
||||
sessions: Default::default(),
|
||||
cache: options.cache.map(Cache::new),
|
||||
address: options.listen,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use axum::extract::State;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::get;
|
||||
|
|
@ -10,17 +12,19 @@ use crate::api::Context;
|
|||
|
||||
pub fn router(ctx: Context) -> Router {
|
||||
let node_id = ctx.profile.public_key;
|
||||
let address = ctx.address;
|
||||
|
||||
Router::new()
|
||||
.route("/node", get(node_handler))
|
||||
.with_state(node_id)
|
||||
.with_state((node_id, address))
|
||||
}
|
||||
|
||||
/// Return the node id for the node identity.
|
||||
/// `GET /node`
|
||||
async fn node_handler(State(node_id): State<NodeId>) -> impl IntoResponse {
|
||||
async fn node_handler(State((node_id, address)): State<(NodeId, SocketAddr)>) -> impl IntoResponse {
|
||||
let response = json!({
|
||||
"id": node_id.to_string(),
|
||||
"address": address.to_string(),
|
||||
});
|
||||
|
||||
Json(response)
|
||||
|
|
|
|||
Loading…
Reference in New Issue