.with(TracingMiddleware::default())
.build();
+ let context = LemmyContext::create(
+ pool.clone(),
+ client.clone(),
+ secret.clone(),
+ rate_limit_cell.clone(),
+ );
+
if scheduled_tasks_enabled {
// Schedules various cleanup tasks for the DB
- thread::spawn(move || {
- scheduled_tasks::setup(db_url, user_agent).expect("Couldn't set up scheduled_tasks");
+ thread::spawn({
+ let context = context.clone();
+ move || {
+ scheduled_tasks::setup(db_url, user_agent, context)
+ .expect("Couldn't set up scheduled_tasks");
+ }
});
}
// Create Http server with websocket support
let settings_bind = settings.clone();
HttpServer::new(move || {
- let context = LemmyContext::create(
- pool.clone(),
- client.clone(),
- secret.clone(),
- rate_limit_cell.clone(),
- );
-
+ let context = context.clone();
let federation_config = FederationConfig::builder()
.domain(settings.hostname.clone())
.app_data(context.clone())
.build()
.expect("configure federation");
- let cors_origin = std::env::var("LEMMY_CORS_ORIGIN").unwrap_or_default();
-
let cors_config = if cfg!(debug_assertions) {
Cors::permissive()
} else {
- Cors::default().allowed_origin(&cors_origin)
+ 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())
};
App::new()
- .wrap(middleware::Logger::default())
+ .wrap(middleware::Logger::new(
+ // This is the default log format save for the usage of %{r}a over %a to guarantee to record the client's (forwarded) IP and not the last peer address, since the latter is frequently just a reverse proxy
+ "%{r}a '%r' %s %b '%{Referer}i' '%{User-Agent}i' %T",
+ ))
.wrap(cors_config)
.wrap(TracingLogger::<QuieterRootSpanBuilder>::new())
.app_data(Data::new(context))