From 5137ffa34f9d28f287c5fdfaa5d1b08ba15ecc93 Mon Sep 17 00:00:00 2001 From: Tony Klink Date: Mon, 15 Jan 2024 17:58:27 -0600 Subject: [PATCH] First iteration on NIP-11 --- src/relay/handler.rs | 14 ++++++++++++++ src/relay/routes.rs | 14 +++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/relay/handler.rs b/src/relay/handler.rs index 5189103..d264ca8 100644 --- a/src/relay/handler.rs +++ b/src/relay/handler.rs @@ -10,3 +10,17 @@ pub async fn ws_handler( ) -> Result { Ok(ws.on_upgrade(move |socket| ws::client_connection(socket, context, real_client_ip))) } + +pub async fn relay_config(header: String) -> Result { + if header != "application/nostr+json" { + Err(warp::reject::not_found()) + } else { + let res = serde_json::json!({ + "name": "Zhitno.st", + "description": "Very *special* nostr relay", + "software": "sneedstr", + "version": "0.1.0" + }); + Ok(warp::reply::json(&res)) + } +} diff --git a/src/relay/routes.rs b/src/relay/routes.rs index ad78584..2c6282c 100644 --- a/src/relay/routes.rs +++ b/src/relay/routes.rs @@ -12,12 +12,16 @@ pub fn routes(context: Context) -> impl Filter impl Filter + Clone { // let real_client_ip = warp::header::optional::("X-Real-IP"); let real_client_ip = warp::addr::remote(); + let accept_application_json_header = warp::header::header("Accept"); - warp::path::end() - .and(warp::ws()) - .and(with_context(context)) - .and(real_client_ip) - .and_then(handler::ws_handler) + warp::path::end().and( + accept_application_json_header + .and_then(handler::relay_config) + .or(warp::ws() + .and(with_context(context)) + .and(real_client_ip) + .and_then(handler::ws_handler)), + ) } fn static_files() -> impl Filter + Clone {