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 — Tidepool's WS port is a reverse proxy
19 /// onto this. Defaults to `ws://127.0.0.1:8900`, matching Surfpool's
20 /// default WS port.
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 /// Fetch off-chain metadata JSON (image/description/attributes/
41 /// files) during `getAsset` and fold it into the DAS response —
42 /// matches real Helius. Supports `http(s)://` + `file://`, fails
43 /// soft on any error. Set `false` (CLI `--no-offchain-metadata`)
44 /// for hermetic / fully-offline runs. Default: true.
45 pub offchain_metadata: bool,
46}
47
48impl Default for ServerConfig {
49 fn default() -> Self {
50 Self {
51 port: 8897,
52 ws_port: None,
53 upstream_url: "http://127.0.0.1:8899".into(),
54 upstream_ws_url: "ws://127.0.0.1:8900".into(),
55 rpc_timeout: Duration::from_secs(10),
56 index_trees: Vec::new(),
57 db: None,
58 snapshots: Vec::new(),
59 offchain_metadata: true,
60 }
61 }
62}