diff --git a/src/relay/handler.rs b/src/relay/handler.rs index 4295254..ea59ea2 100644 --- a/src/relay/handler.rs +++ b/src/relay/handler.rs @@ -11,18 +11,12 @@ pub async fn ws_handler( Ok(ws.on_upgrade(move |socket| ws::client_connection(socket, context, real_client_ip))) } -pub async fn relay_config(header: String) -> Result { +pub async fn relay_config(header: String, context: Context) -> Result { if header != "application/nostr+json" { Err(warp::reject::not_found()) } else { - let res = serde_json::json!({ - "contact": "klink@zhitno.st", - "name": "zhitno.st", - "description": "Very *special* nostr relay", - "supported_nips": [ 1, 9, 11, 12, 15, 16, 20, 22, 28, 33 ], - "software": "git+https://git.zhitno.st/Klink/sneedstr.git", - "version": "0.1.0" - }); - Ok(warp::reply::json(&res)) + let config = context.config.get_relay_config_json(); + + Ok(warp::reply::json(&config)) } } diff --git a/src/relay/routes.rs b/src/relay/routes.rs index d30cfae..c1159ca 100644 --- a/src/relay/routes.rs +++ b/src/relay/routes.rs @@ -12,19 +12,15 @@ 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"); let cors = warp::cors().allow_any_origin(); - warp::path::end().and( - accept_application_json_header - .and_then(handler::relay_config) - .with(&cors) - .or(warp::ws() - .and(with_context(context)) + 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)), - ) + .with(&cors)); + + relay_information_document_path.or(nostr_relay_path) } fn static_files() -> impl Filter + Clone { diff --git a/src/utils/config.rs b/src/utils/config.rs index 78ed854..9644b99 100644 --- a/src/utils/config.rs +++ b/src/utils/config.rs @@ -45,7 +45,7 @@ impl Config { "description": "Very *special* nostr relay", "supported_nips": [ 1, 2, 9, 11, 12, 15, 16, 20, 22, 28, 33, 40, 45 ], "software": "git+https://git.zhitno.st/Klink/sneedstr.git", - "version": "0.1.0" + "version": "0.1.1" }) } }