First iteration on NIP-11

This commit is contained in:
Tony Klink 2024-01-15 17:58:27 -06:00
parent a9817b77f9
commit 5137ffa34f
Signed by: klink
GPG key ID: 85175567C4D19231
2 changed files with 23 additions and 5 deletions

View file

@ -10,3 +10,17 @@ pub async fn ws_handler(
) -> Result<impl Reply, Rejection> { ) -> Result<impl Reply, Rejection> {
Ok(ws.on_upgrade(move |socket| ws::client_connection(socket, context, real_client_ip))) Ok(ws.on_upgrade(move |socket| ws::client_connection(socket, context, real_client_ip)))
} }
pub async fn relay_config(header: String) -> Result<impl Reply, Rejection> {
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))
}
}

View file

@ -12,12 +12,16 @@ pub fn routes(context: Context) -> impl Filter<Extract = impl Reply, Error = Rej
fn index(context: Context) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 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::header::optional::<std::net::SocketAddr>("X-Real-IP");
let real_client_ip = warp::addr::remote(); let real_client_ip = warp::addr::remote();
let accept_application_json_header = warp::header::header("Accept");
warp::path::end() warp::path::end().and(
.and(warp::ws()) accept_application_json_header
.and_then(handler::relay_config)
.or(warp::ws()
.and(with_context(context)) .and(with_context(context))
.and(real_client_ip) .and(real_client_ip)
.and_then(handler::ws_handler) .and_then(handler::ws_handler)),
)
} }
fn static_files() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { fn static_files() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {