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/mod.rs | |
| parent | 98c6fa4bfa897ff0b8f9c95ea698d4d065b5e9f3 (diff) | |
add landing page and nostr-relay-builder relay on same port
Diffstat (limited to 'src/http/mod.rs')
| -rw-r--r-- | src/http/mod.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs new file mode 100644 index 0000000..286e8ff --- /dev/null +++ b/src/http/mod.rs | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /// HTTP Server Module | ||
| 2 | /// | ||
| 3 | /// Provides actix-web HTTP server with WebSocket upgrade support for the Nostr relay. | ||
| 4 | |||
| 5 | pub mod landing; | ||
| 6 | pub mod websocket; | ||
| 7 | |||
| 8 | use actix_web::{middleware, web, App, HttpServer}; | ||
| 9 | use nostr_relay_builder::LocalRelay; | ||
| 10 | |||
| 11 | use crate::config::Config; | ||
| 12 | |||
| 13 | /// Start the HTTP server with integrated Nostr relay | ||
| 14 | pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> { | ||
| 15 | let bind_addr = config.bind_address.clone(); | ||
| 16 | |||
| 17 | tracing::info!("Starting HTTP server on {}", bind_addr); | ||
| 18 | |||
| 19 | HttpServer::new(move || { | ||
| 20 | App::new() | ||
| 21 | .app_data(web::Data::new(config.clone())) | ||
| 22 | .app_data(web::Data::new(relay.clone())) | ||
| 23 | .wrap(middleware::Logger::default()) | ||
| 24 | .route("/", web::get().to(landing::handle)) | ||
| 25 | }) | ||
| 26 | .bind(&bind_addr)? | ||
| 27 | .run() | ||
| 28 | .await?; | ||
| 29 | |||
| 30 | Ok(()) | ||
| 31 | } \ No newline at end of file | ||