tidepool_server/config.rs
1//! Server configuration. Shape mirrors the TS `ProxyOptions` plus
2//! server-specific knobs (port, WS URL override).
3
4use std::path::PathBuf;
5use std::time::Duration;
6
7#[derive(Debug, Clone)]
8pub struct ServerConfig {
9 /// HTTP port to bind.
10 pub port: u16,
11 /// Dedicated WebSocket port. When `None`, derives as `port + 1`.
12 /// Tests set this explicitly to avoid parallel port-allocation
13 /// races where two test runs pick adjacent HTTP ports and collide
14 /// on each other's WS.
15 pub ws_port: Option<u16>,
16 /// Upstream Solana RPC endpoint for passthrough + DAS fetch flow.
17 pub upstream_url: String,
18 /// Upstream WebSocket URL — used by the (future) signatureSubscribe
19 /// polyfill to forward non-polyfilled subscriptions. Defaults to
20 /// `ws://<upstream host>:8900`.
21 pub upstream_ws_url: String,
22 /// RPC call timeout applied to every upstream fetch.
23 pub rpc_timeout: Duration,
24 /// Bubblegum trees to backfill on startup. Empty = cNFT support
25 /// disabled until a runtime `tidepool_indexTree` call.
26 pub index_trees: Vec<String>,
27 /// When set, persist cNFT/DAS/webhook state to a single SQLite
28 /// file. Mirrors Surfpool's `--db` flag; accepts a filesystem
29 /// path (typically ending in `.sqlite`) or the string `:memory:`
30 /// for an explicit ephemeral run.
31 ///
32 /// When `None`, stores run in-memory and state is lost on
33 /// restart. Default behavior.
34 pub db: Option<PathBuf>,
35 /// Snapshot files to load at boot, in order. Each file is a
36 /// `SnapshotBlob` envelope returned by
37 /// `tidepool_exportTreeSnapshot`. Applied before the HTTP server
38 /// starts accepting requests. Mirrors Surfpool's `--snapshot`.
39 pub snapshots: Vec<PathBuf>,
40}
41
42impl Default for ServerConfig {
43 fn default() -> Self {
44 Self {
45 port: 8897,
46 ws_port: None,
47 upstream_url: "http://127.0.0.1:8899".into(),
48 upstream_ws_url: "ws://127.0.0.1:8900".into(),
49 rpc_timeout: Duration::from_secs(10),
50 index_trees: Vec::new(),
51 db: None,
52 snapshots: Vec::new(),
53 }
54 }
55}