An easy-to-host PDS on the ATProtocol, MacOS. Grandma-approved.

feat(relay): add reqwest::Client to AppState for outbound HTTP (MM-89)

authored by malpercio.dev and committed by

Tangled d256b101 5c7c90d7

+21 -9
+14 -9
crates/relay/src/app.rs
··· 8 8 }; 9 9 use common::{ApiError, Config, ErrorCode}; 10 10 use opentelemetry::propagation::Extractor; 11 + use reqwest::Client; 11 12 use tower_http::{cors::CorsLayer, trace::TraceLayer}; 12 13 use tracing_opentelemetry::OpenTelemetrySpanExt; 13 14 ··· 76 77 pub struct AppState { 77 78 pub config: Arc<Config>, 78 79 pub db: sqlx::SqlitePool, 80 + pub http_client: Client, 79 81 } 80 82 81 83 /// Build the Axum router with middleware and routes. ··· 111 113 ) 112 114 } 113 115 114 - /// Build a minimal `AppState` backed by an in-memory SQLite database. 115 - /// The pool is fully migrated, so the schema is present and ready for handler tests. 116 116 #[cfg(test)] 117 117 pub(crate) async fn test_state() -> AppState { 118 + test_state_with_plc_url("https://plc.directory".to_string()).await 119 + } 120 + 121 + #[cfg(test)] 122 + pub async fn test_state_with_plc_url(plc_directory_url: String) -> AppState { 123 + use crate::db::{open_pool, run_migrations}; 118 124 use common::{BlobsConfig, IrohConfig, OAuthConfig, TelemetryConfig}; 119 125 use std::path::PathBuf; 120 126 121 - let pool = crate::db::open_pool("sqlite::memory:") 122 - .await 123 - .expect("failed to open test pool"); 124 - crate::db::run_migrations(&pool) 125 - .await 126 - .expect("failed to run test migrations"); 127 + let db = open_pool("sqlite::memory:").await.expect("test pool"); 128 + run_migrations(&db).await.expect("test migrations"); 129 + 127 130 AppState { 128 131 config: Arc::new(Config { 129 132 bind_address: "127.0.0.1".to_string(), ··· 142 145 telemetry: TelemetryConfig::default(), 143 146 admin_token: None, 144 147 signing_key_master_key: None, 148 + plc_directory_url, 145 149 }), 146 - db: pool, 150 + db, 151 + http_client: Client::new(), 147 152 } 148 153 } 149 154
+2
crates/relay/src/main.rs
··· 1 1 use anyhow::Context; 2 2 use clap::Parser; 3 + use reqwest::Client; 3 4 use std::{path::PathBuf, sync::Arc}; 4 5 5 6 mod app; ··· 99 100 let state = app::AppState { 100 101 config: Arc::new(config), 101 102 db: pool, 103 + http_client: Client::new(), 102 104 }; 103 105 104 106 let listener = tokio::net::TcpListener::bind(&addr)
+1
crates/relay/src/routes/auth.rs
··· 67 67 AppState { 68 68 config: Arc::new(config), 69 69 db: base.db, 70 + http_client: base.http_client, 70 71 } 71 72 } 72 73
+2
crates/relay/src/routes/create_signing_key.rs
··· 124 124 AppState { 125 125 config: Arc::new(config), 126 126 db: base.db, 127 + http_client: base.http_client, 127 128 } 128 129 } 129 130 ··· 383 384 let state = AppState { 384 385 config: Arc::new(config), 385 386 db: base.db, 387 + http_client: base.http_client, 386 388 }; 387 389 388 390 let response = app(state)
+1
crates/relay/src/routes/describe_server.rs
··· 126 126 let state = AppState { 127 127 config: Arc::new(config), 128 128 db: base.db, 129 + http_client: base.http_client, 129 130 }; 130 131 131 132 let response = app(state)
+1
crates/relay/src/routes/test_utils.rs
··· 14 14 AppState { 15 15 config: Arc::new(config), 16 16 db: base.db, 17 + http_client: base.http_client, 17 18 } 18 19 }