diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-20 21:36:09 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-20 21:36:09 +0000 |
| commit | 89c69eae8e75d2b00794087d9ef74fd4856d0f88 (patch) | |
| tree | 2a1055d98c6de7ec0b83e857817569b2203aa0e9 /src/http/landing.rs | |
| parent | 62bcfda39d51a459fbf0a7fa48ee9e2ac8505780 (diff) | |
replace actix with hyper
Diffstat (limited to 'src/http/landing.rs')
| -rw-r--r-- | src/http/landing.rs | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/src/http/landing.rs b/src/http/landing.rs index 976ec50..55ffb26 100644 --- a/src/http/landing.rs +++ b/src/http/landing.rs | |||
| @@ -1,40 +1,15 @@ | |||
| 1 | /// Landing Page Handler | 1 | /// Landing Page Handler |
| 2 | /// | 2 | /// |
| 3 | /// Serves the HTML landing page or upgrades to WebSocket for Nostr relay connections. | 3 | /// Generates HTML landing page for the Nostr relay. |
| 4 | use actix_web::{web, HttpRequest, HttpResponse, Result}; | ||
| 5 | use nostr_relay_builder::LocalRelay; | ||
| 6 | |||
| 7 | use crate::config::Config; | 4 | use crate::config::Config; |
| 8 | 5 | ||
| 9 | /// Handle landing page or WebSocket upgrade | 6 | /// Generate the HTML landing page |
| 10 | pub async fn handle( | 7 | pub fn get_html(config: &Config) -> String { |
| 11 | req: HttpRequest, | 8 | format!( |
| 12 | stream: web::Payload, | ||
| 13 | config: web::Data<Config>, | ||
| 14 | relay: web::Data<LocalRelay>, | ||
| 15 | ) -> Result<HttpResponse> { | ||
| 16 | // Check if this is a WebSocket upgrade request | ||
| 17 | if let Some(upgrade) = req.headers().get("upgrade") { | ||
| 18 | if upgrade | ||
| 19 | .to_str() | ||
| 20 | .unwrap_or("") | ||
| 21 | .eq_ignore_ascii_case("websocket") | ||
| 22 | { | ||
| 23 | // Delegate to WebSocket handler | ||
| 24 | return crate::http::websocket::handle(req, stream, relay).await; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | // Otherwise, serve the landing page | ||
| 29 | let html = format!( | ||
| 30 | include_str!("../../templates/landing.html"), | 9 | include_str!("../../templates/landing.html"), |
| 31 | relay_name = config.relay_name, | 10 | relay_name = config.relay_name, |
| 32 | relay_description = config.relay_description, | 11 | relay_description = config.relay_description, |
| 33 | domain = config.domain, | 12 | domain = config.domain, |
| 34 | bind_address = config.bind_address, | 13 | bind_address = config.bind_address, |
| 35 | ); | 14 | ) |
| 36 | |||
| 37 | Ok(HttpResponse::Ok() | ||
| 38 | .content_type("text/html; charset=utf-8") | ||
| 39 | .body(html)) | ||
| 40 | } | 15 | } |