Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Add socketAddress to `/node` endpoint
Sebastian Martinez committed 2 years ago
commit df2251f6ee44ac6b15d0500f4130b3c7aa7604b4
parent d45cce1df5521e6f8771d31e742c35c15b2c42df
2 files changed +9 -2
modified 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<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,
        }
    }

modified 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<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)