Add support for querying NIP-05 on /.well-known/nostr.json?name=username

This commit is contained in:
Tony Klink 2024-01-30 11:43:03 -06:00
parent e1306608ef
commit 377da44eed
Signed by: klink
GPG key ID: 85175567C4D19231
12 changed files with 278 additions and 101 deletions

View file

@ -6,19 +6,24 @@ use warp::{Filter, Rejection, Reply};
pub fn routes(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
let cors = warp::cors().allow_any_origin();
static_files().or(index(context)).with(cors)
static_files().or(index(context)).with(&cors)
}
fn index(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
// let real_client_ip = warp::header::optional::<std::net::SocketAddr>("X-Real-IP");
let real_client_ip = warp::addr::remote();
let cors = warp::cors().allow_any_origin();
let relay_information_document_path = warp::path::end().and(warp::header::header("Accept").and(with_context(context.clone())).and_then(handler::relay_config)).with(&cors);
let nostr_relay_path = warp::path::end().and(warp::ws().and(with_context(context.clone()))
.and(real_client_ip)
.and_then(handler::ws_handler)
.with(&cors));
let relay_information_document_path = warp::path::end().and(
warp::header::header("Accept")
.and(with_context(context.clone()))
.and_then(handler::relay_config),
);
let nostr_relay_path = warp::path::end().and(
warp::ws()
.and(with_context(context.clone()))
.and(real_client_ip)
.and_then(handler::ws_handler),
);
relay_information_document_path.or(nostr_relay_path)
}