outsource app creation as a preparation for testing

This commit is contained in:
Lennart
2024-02-10 16:30:13 +01:00
parent ae06d0b9a7
commit f81ca9cff3
2 changed files with 44 additions and 23 deletions

36
src/app.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::sync::Arc;
use actix_web::body::MessageBody;
use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse};
use actix_web::middleware::{Logger, NormalizePath};
use actix_web::{web, App};
use rustical_api::configure_api;
use rustical_auth::CheckAuthentication;
use rustical_caldav::{configure_dav, configure_well_known};
use rustical_store::calendar::CalendarStore;
use tokio::sync::RwLock;
pub fn make_app<CS: CalendarStore + ?Sized, A: CheckAuthentication>(
cal_store: Arc<RwLock<CS>>,
auth: Arc<A>,
) -> App<
impl ServiceFactory<
ServiceRequest,
Response = ServiceResponse<impl MessageBody>,
Config = (),
InitError = (),
Error = actix_web::Error,
>,
> {
App::new()
.wrap(Logger::new("[%s] %r"))
.wrap(NormalizePath::trim())
.service(web::scope("/caldav").configure(|cfg| {
configure_dav(cfg, "/caldav".to_string(), auth.clone(), cal_store.clone())
}))
.service(
web::scope("/.well-known")
.configure(|cfg| configure_well_known(cfg, "/caldav".to_string())),
)
.service(web::scope("/api").configure(|cfg| configure_api(cfg, cal_store.clone().into())))
}