mod api; mod view; pub use self::api::ApiDoc; use std::sync::Arc; use axum::{Extension, Router}; use migration::sea_orm::DatabaseConnection; use crate::{ configs::{ProgramSettings, server::CORSSettings}, middlewares, services::{ AppService, ServiceState, auth::authentication::{AuthenticationService, strategies::password::PasswordStrategy}, }, }; #[derive(Clone)] pub struct AppState { pub database_connection: Arc, pub service: Arc, pub config: Arc, } pub struct AuthStrategy { pub password: ServiceState, } pub struct AuthState { pub strategy: AuthStrategy, pub authentication: ServiceState, } pub fn get_root_router( state: impl Into>, cors_settings: Arc, ) -> Router { let mut router = Router::new(); let state = state.into(); router = router .nest("/api", api::get_api_router(state.clone())) .merge(view::get_view_router()); router = middlewares::apply_root_middleware(router, state.clone(), cors_settings); router = router.layer(Extension(state.clone())); router } #[cfg(test)] mod tests { use super::*; #[test] fn ensure_state_send_sync() { fn assert_send_sync() {} assert_send_sync::(); } }