use crate::{code_migrations::run_advanced_migrations, root_span_builder::QuieterRootSpanBuilder};
use activitypub_federation::config::{FederationConfig, FederationMiddleware};
use actix_cors::Cors;
-use actix_web::{middleware, web::Data, App, HttpServer, Result};
+use actix_web::{
+ middleware::{self, ErrorHandlers},
+ web::Data,
+ App,
+ HttpServer,
+ Result,
+};
use lemmy_api_common::{
context::LemmyContext,
lemmy_db_views::structs::SiteView,
utils::{build_db_pool, get_database_url, run_migrations},
};
use lemmy_routes::{feeds, images, nodeinfo, webfinger};
-use lemmy_utils::{error::LemmyError, rate_limit::RateLimitCell, settings::SETTINGS};
+use lemmy_utils::{
+ error::LemmyError,
+ rate_limit::RateLimitCell,
+ response::jsonify_plain_text_errors,
+ settings::SETTINGS,
+ SYNCHRONOUS_FEDERATION,
+};
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
use reqwest_tracing::TracingMiddleware;
let pool = build_db_pool(&settings).await?;
// Run the Code-required migrations
- run_advanced_migrations(&pool, &settings).await?;
+ run_advanced_migrations(&mut (&pool).into(), &settings).await?;
// Initialize the secrets
- let secret = Secret::init(&pool)
+ let secret = Secret::init(&mut (&pool).into())
.await
.expect("Couldn't initialize secrets.");
// Make sure the local site is set up.
- let site_view = SiteView::read_local(&pool)
+ let site_view = SiteView::read_local(&mut (&pool).into())
.await
.expect("local site not set up");
let local_site = site_view.local_site;
.http_fetch_limit(FEDERATION_HTTP_FETCH_LIMIT)
.worker_count(settings.worker_count)
.retry_count(settings.retry_count)
- .debug(cfg!(debug_assertions))
+ .debug(*SYNCHRONOUS_FEDERATION)
.http_signature_compat(true)
- .url_verifier(Box::new(VerifyUrlData(context.pool().clone())))
+ .url_verifier(Box::new(VerifyUrlData(context.inner_pool().clone())))
.build()
.await?;
// Create Http server with websocket support
HttpServer::new(move || {
- let cors_config = if cfg!(debug_assertions) {
- Cors::permissive()
- } else {
- let cors_origin = std::env::var("LEMMY_CORS_ORIGIN").unwrap_or("http://localhost".into());
- Cors::default()
- .allowed_origin(&cors_origin)
- .allowed_origin(&settings.get_protocol_and_hostname())
+ let cors_origin = std::env::var("LEMMY_CORS_ORIGIN");
+ let cors_config = match (cors_origin, cfg!(debug_assertions)) {
+ (Ok(origin), false) => Cors::default()
+ .allowed_origin(&origin)
+ .allowed_origin(&settings.get_protocol_and_hostname()),
+ _ => Cors::default()
+ .allow_any_origin()
+ .allow_any_method()
+ .allow_any_header()
+ .expose_any_header()
+ .max_age(3600),
};
let app = App::new()
.wrap(middleware::Compress::default())
.wrap(cors_config)
.wrap(TracingLogger::<QuieterRootSpanBuilder>::new())
+ .wrap(ErrorHandlers::new().default_handler(jsonify_plain_text_errors))
.app_data(Data::new(context.clone()))
.app_data(Data::new(rate_limit_cell.clone()))
.wrap(FederationMiddleware::new(federation_config.clone()));