diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 11:55:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 15:43:29 +0000 |
| commit | fa065ad128882755f2a988d6203b59a2ab5e38ff (patch) | |
| tree | e8326de70a6e6ea56b5bf4250e0a00a3cda4afed /src/http/landing.rs | |
| parent | 98c6fa4bfa897ff0b8f9c95ea698d4d065b5e9f3 (diff) | |
add landing page and nostr-relay-builder relay on same port
Diffstat (limited to 'src/http/landing.rs')
| -rw-r--r-- | src/http/landing.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/http/landing.rs b/src/http/landing.rs new file mode 100644 index 0000000..35e49e5 --- /dev/null +++ b/src/http/landing.rs | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /// Landing Page Handler | ||
| 2 | /// | ||
| 3 | /// Serves the HTML landing page or upgrades to WebSocket for Nostr relay connections. | ||
| 4 | |||
| 5 | use actix_web::{web, HttpRequest, HttpResponse, Result}; | ||
| 6 | use nostr_relay_builder::LocalRelay; | ||
| 7 | |||
| 8 | use crate::config::Config; | ||
| 9 | |||
| 10 | /// Handle landing page or WebSocket upgrade | ||
| 11 | pub async fn handle( | ||
| 12 | req: HttpRequest, | ||
| 13 | stream: web::Payload, | ||
| 14 | config: web::Data<Config>, | ||
| 15 | relay: web::Data<LocalRelay>, | ||
| 16 | ) -> Result<HttpResponse> { | ||
| 17 | // Check if this is a WebSocket upgrade request | ||
| 18 | if let Some(upgrade) = req.headers().get("upgrade") { | ||
| 19 | if upgrade.to_str().unwrap_or("").eq_ignore_ascii_case("websocket") { | ||
| 20 | // Delegate to WebSocket handler | ||
| 21 | return crate::http::websocket::handle(req, stream, relay).await; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | // Otherwise, serve the landing page | ||
| 26 | let html = format!( | ||
| 27 | include_str!("../../templates/landing.html"), | ||
| 28 | relay_name = config.relay_name, | ||
| 29 | relay_description = config.relay_description, | ||
| 30 | domain = config.domain, | ||
| 31 | bind_address = config.bind_address, | ||
| 32 | ); | ||
| 33 | |||
| 34 | Ok(HttpResponse::Ok() | ||
| 35 | .content_type("text/html; charset=utf-8") | ||
| 36 | .body(html)) | ||
| 37 | } \ No newline at end of file | ||