Skip to content

Commit

Permalink
feat: add custom relay page
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-04 authored and scsibug committed Sep 6, 2024
1 parent 05411eb commit 6329acd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
3 changes: 3 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Info {
pub contact: Option<String>,
pub favicon: Option<String>,
pub relay_icon: Option<String>,
pub relay_page: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -285,6 +286,7 @@ impl Default for Settings {
contact: None,
favicon: None,
relay_icon: None,
relay_page: None,
},
diagnostics: Diagnostics { tracing: false },
database: Database {
Expand Down
15 changes: 15 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6329acd

Please sign in to comment.