diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index e39d0585..0d7bb5de 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -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, sessions: Arc>>, cache: Option, + address: SocketAddr, } impl Context { @@ -46,6 +48,7 @@ impl Context { profile, sessions: Default::default(), cache: options.cache.map(Cache::new), + address: options.listen, } } diff --git a/radicle-httpd/src/api/v1/node.rs b/radicle-httpd/src/api/v1/node.rs index 1dfea613..65a08a69 100644 --- a/radicle-httpd/src/api/v1/node.rs +++ b/radicle-httpd/src/api/v1/node.rs @@ -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) -> 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)