credence_lib/server/
site.rs1use super::{
2 super::{configuration::*, coordinator::*},
3 configuration::*,
4 routers::*,
5};
6
7use {axum::routing::*, kutil::http::axum::*, std::path::*};
8
9#[derive(Clone, Debug)]
15pub struct Site {
16 pub configuration: CredenceConfiguration,
18
19 pub router: Router,
21}
22
23impl Site {
24 pub fn new<PathT>(assets_path: PathT, shutdown: &Shutdown) -> Result<Self, ConfigurationError>
26 where
27 PathT: AsRef<Path>,
28 {
29 let assets_path = assets_path.as_ref();
30
31 if !assets_path.exists() {
32 return Err(format!("assets path does not exist: {}", assets_path.display()).into());
33 } else if !assets_path.is_dir() {
34 return Err(format!("assets path is not a directory: {}", assets_path.display()).into());
35 }
36
37 let configuration = load_configuration(assets_path)?;
38 let cache = configuration.caching.cache();
39 let router = new_site_router(shutdown, &cache, &configuration);
40
41 Ok(Self { configuration, router })
42 }
43
44 pub fn new_coordinator(&self) -> Result<Option<Coordinator>, ConfigurationError> {
46 Ok(self.configuration.files.coordinate.new_coordinator()?)
47 }
48}