Skip to main content

matrix_bridge_telegram/
web.rs

1pub mod health;
2pub mod metrics;
3pub mod provisioning;
4pub mod thirdparty;
5
6use std::sync::Arc;
7
8use salvo::Listener;
9
10use anyhow::Result;
11
12use crate::bridge::BridgeCore;
13use crate::config::Config;
14use crate::db::DatabaseManager;
15use crate::matrix::MatrixAppservice;
16
17pub struct WebServer {
18    config: Arc<Config>,
19}
20
21impl WebServer {
22    pub async fn new(
23        config: Arc<Config>,
24        _matrix_client: Arc<MatrixAppservice>,
25        _db_manager: Arc<DatabaseManager>,
26        _bridge: Arc<BridgeCore>,
27    ) -> Result<Self> {
28        Ok(Self { config })
29    }
30
31    pub async fn start(&self) -> Result<()> {
32        let bind_addr: String = format!("{}:{}", self.config.bridge.bind_address, self.config.bridge.port);
33        tracing::info!("Web server listening on {}", bind_addr);
34        
35        let router = salvo::Router::new()
36            .push(salvo::Router::with_path("/health").get(health::health_check));
37        
38        let service = salvo::Service::new(router);
39        let acceptor = salvo::conn::TcpListener::new(bind_addr).bind().await;
40        salvo::Server::new(acceptor).serve(service).await;
41        
42        Ok(())
43    }
44}