1pub mod api;
2pub mod appservice;
3pub mod cache;
4pub mod config;
5pub mod error;
6pub mod log;
7pub mod middleware;
8pub mod ping;
9pub mod requests;
10pub mod rooms;
11pub mod server;
12pub mod space;
13pub mod utils;
14
15use std::sync::Arc;
16use std::time::Duration;
17
18use reqwest::Client;
19
20pub type ProxyClient = reqwest::Client;
21
22#[derive(Clone)]
23pub struct AppState {
24 pub config: config::Config,
25 pub proxy: ProxyClient,
26 pub appservice: appservice::AppService,
27 pub transaction_store: ping::TransactionStore,
28 pub cache: cache::Cache,
29}
30
31impl AppState {
32 pub async fn new(config: config::Config) -> Result<Arc<Self>, anyhow::Error> {
33 let client = Client::builder()
34 .timeout(Duration::from_secs(30))
35 .connect_timeout(Duration::from_secs(10))
36 .pool_max_idle_per_host(10)
37 .pool_idle_timeout(Duration::from_secs(90))
38 .user_agent("commune-public-appservice")
39 .build()?;
40
41 let appservice = appservice::AppService::new(&config).await?;
42
43 let cache = cache::Cache::new(&config).await?;
44
45 let transaction_store = ping::TransactionStore::new();
46
47 Ok(Arc::new(Self {
48 config,
49 proxy: client,
50 appservice,
51 transaction_store,
52 cache,
53 }))
54 }
55}
56
57use clap::Parser;
58
59#[derive(Parser)]
60pub struct Args {
61 #[arg(short, long, default_value = "config.toml")]
62 pub config: std::path::PathBuf,
63 #[arg(short, long, default_value = "8989")]
64 pub port: u16,
65}
66
67impl Args {
68 pub fn build() -> Self {
69 Args::parse()
70 }
71}