Skip to content
1        10        20        30        40        50        60        70        80        901use std::env;23use actix_web::{App, HttpServer, web};45#[actix_web::main]6async fn main() -> std::io::Result<()> {7    let db_path = env::var("DIAL_DB").unwrap_or_else(|_| "dial.db".to_string());8    let bind = env::var("DIAL_BIND").unwrap_or_else(|_| "127.0.0.1:8080".to_string());9    // Required: the broker refuses to start without a key rather than run open.10    let api_key = env::var("DIAL_API_KEY")11        .ok()12        .filter(|key| !key.is_empty())13        .ok_or_else(|| std::io::Error::other("DIAL_API_KEY must be set to a non-empty value"))?;1415    let db = dial::open(&db_path).map_err(std::io::Error::other)?;16    let data = web::Data::new(db);17    let key = web::Data::new(dial::ApiKey(api_key));1819    println!("dial listening on {bind}, storing messages in {db_path}, API key required");20    HttpServer::new(move || {21        App::new()22            .app_data(data.clone())23            .app_data(key.clone())24            .configure(dial::configure)25    })26    .bind(bind)?27    .run()28    .await29}