First iteration on NIP-11
This commit is contained in:
parent
a9817b77f9
commit
5137ffa34f
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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(with_context(context))
|
.and_then(handler::relay_config)
|
||||||
.and(real_client_ip)
|
.or(warp::ws()
|
||||||
.and_then(handler::ws_handler)
|
.and(with_context(context))
|
||||||
|
.and(real_client_ip)
|
||||||
|
.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 {
|
||||||
|
|
Loading…
Reference in a new issue