upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/http/mod.rs
blob: b434c694b1e0db891cbb0d41d8ace4bb7ca371e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// HTTP Server Module
///
/// Provides actix-web HTTP server with WebSocket upgrade support for the Nostr relay.
pub mod landing;
pub mod websocket;

use actix_web::{middleware, web, App, HttpServer};
use nostr_relay_builder::LocalRelay;

use crate::config::Config;

/// Start the HTTP server with integrated Nostr relay
pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> {
    let bind_addr = config.bind_address.clone();

    tracing::info!("Starting HTTP server on {}", bind_addr);

    HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(config.clone()))
            .app_data(web::Data::new(relay.clone()))
            .wrap(middleware::Logger::default())
            .route("/", web::get().to(landing::handle))
    })
    .bind(&bind_addr)?
    .run()
    .await?;

    Ok(())
}