From 6329acd82b39906560b33cb0b543b7cbe724b060 Mon Sep 17 00:00:00 2001 From: kuba Date: Mon, 2 Sep 2024 11:03:06 +0200 Subject: [PATCH] feat: add custom relay page --- README.md | 1 + config.toml | 3 +++ src/config.rs | 2 ++ src/server.rs | 15 +++++++++++++++ 4 files changed, 21 insertions(+) diff --git a/README.md b/README.md index e998ac4..6e9ede5 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ be mounted into a docker container like so: $ docker run -it -p 7000:8080 \ --mount src=$(pwd)/config.toml,target=/usr/src/app/config.toml,type=bind \ --mount src=$(pwd)/data,target=/usr/src/app/db,type=bind \ + --mount src=$(pwd)/index.html,target=/usr/src/app/index.html,type=bind \ nostr-rs-relay ``` diff --git a/config.toml b/config.toml index 1b67939..64b32bf 100644 --- a/config.toml +++ b/config.toml @@ -23,6 +23,9 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i # URL of Relay's icon. #relay_icon = "https://example.test/img.png" +# Path to custom relay html page +#relay_page = "index.html" + [diagnostics] # Enable tokio tracing (for use with tokio-console) #tracing = false diff --git a/src/config.rs b/src/config.rs index 71a6014..c71cd8b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,6 +14,7 @@ pub struct Info { pub contact: Option, pub favicon: Option, pub relay_icon: Option, + pub relay_page: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -285,6 +286,7 @@ impl Default for Settings { contact: None, favicon: None, relay_icon: None, + relay_page: None, }, diagnostics: Diagnostics { tracing: false }, database: Database { diff --git a/src/server.rs b/src/server.rs index 4a8d87d..52fb328 100644 --- a/src/server.rs +++ b/src/server.rs @@ -194,6 +194,21 @@ async fn handle_web_request( .unwrap()); } + if let Some(relay_file_path) = settings.info.relay_page { + match file_bytes(&relay_file_path) { + Ok(file_content) => { + return Ok(Response::builder() + .status(200) + .header("Content-Type", "text/html; charset=UTF-8") + .body(Body::from(file_content)) + .expect("request builder")); + }, + Err(err) => { + error!("Failed to read relay_page file: {}. Will use default", err); + } + } + } + Ok(Response::builder() .status(200) .header("Content-Type", "text/plain")