use lemmy_utils::{
error::LemmyError,
rate_limit::{rate_limiter::RateLimiter, RateLimit},
- settings::structs::Settings,
+ settings::{structs::Settings, SETTINGS},
};
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
-use parking_lot::Mutex;
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
use reqwest_tracing::TracingMiddleware;
-use std::{env, sync::Arc, thread, time::Duration};
+use std::{
+ env,
+ sync::{Arc, Mutex},
+ thread,
+ time::Duration,
+};
use tracing_actix_web::TracingLogger;
embed_migrations!();
return Ok(());
}
- let settings = Settings::init().expect("Couldn't initialize settings.");
+ let settings = SETTINGS.to_owned();
- init_logging(settings.opentelemetry_url.as_deref())?;
+ init_logging(&settings.opentelemetry_url)?;
// Set up the r2d2 connection pool
let db_url = match get_database_url_from_env() {
let manager = ConnectionManager::<PgConnection>::new(&db_url);
let pool = Pool::builder()
.max_size(settings.database.pool_size)
+ .min_idle(Some(1))
.build(manager)
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
settings.bind, settings.port
);
- let client = Client::builder()
+ let reqwest_client = Client::builder()
.user_agent(build_user_agent(&settings))
.timeout(REQWEST_TIMEOUT)
.build()?;
backoff_exponent: 2,
};
- let client = ClientBuilder::new(client)
+ let client = ClientBuilder::new(reqwest_client.clone())
.with(TracingMiddleware)
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
.build();
+ // Pictrs cannot use the retry middleware
+ let pictrs_client = ClientBuilder::new(reqwest_client.clone())
+ .with(TracingMiddleware)
+ .build();
+
check_private_instance_and_federation_enabled(&pool, &settings).await?;
let chat_server = ChatServer::startup(
.configure(|cfg| api_routes::config(cfg, &rate_limiter))
.configure(|cfg| lemmy_apub::http::routes::config(cfg, &settings))
.configure(feeds::config)
- .configure(|cfg| images::config(cfg, client.clone(), &rate_limiter))
+ .configure(|cfg| images::config(cfg, pictrs_client.clone(), &rate_limiter))
.configure(nodeinfo::config)
.configure(|cfg| webfinger::config(cfg, &settings))
})