From 7dda553918705277c7fa5b903c6a40e4b4a0aa8d Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 21 Nov 2025 04:44:40 +0000 Subject: add nip11 --- src/http/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/http/mod.rs') diff --git a/src/http/mod.rs b/src/http/mod.rs index 4690790..7c0e7bb 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -2,6 +2,7 @@ /// /// Provides hyper HTTP server with WebSocket upgrade support for the Nostr relay. pub mod landing; +pub mod nip11; use std::future::Future; use std::net::SocketAddr; @@ -46,6 +47,32 @@ impl Service> for HttpService { fn call(&self, req: Request) -> Self::Future { let base = Response::builder().header("server", "ngit-grasp"); + // Check for NIP-11 relay information request (Accept: application/nostr+json) + if let Some(accept) = req.headers().get("accept") { + if accept + .to_str() + .map(|s| s.contains("application/nostr+json")) + .unwrap_or(false) + { + let doc = nip11::RelayInformationDocument::from_config(&self.config); + let json = doc.to_json().unwrap_or_else(|e| { + tracing::error!("Failed to serialize NIP-11 document: {}", e); + "{}".to_string() + }); + + tracing::debug!("Serving NIP-11 relay information document to {}", self.remote); + + return Box::pin(async move { + Ok(base + .status(200) + .header("content-type", "application/nostr+json") + .header("access-control-allow-origin", "*") + .body(json) + .unwrap()) + }); + } + } + // Check if this is a WebSocket upgrade request if let (Some(c), Some(w)) = ( req.headers().get("connection"), -- cgit v1.2.3