pzzld_server/workers/serve/
mod.rs

1/*
2    Appellation: serve <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5#[doc(inline)]
6pub use self::{actor::Server, context::ServerContext};
7
8mod actor;
9mod context;
10
11use crate::config::Scope;
12use crate::traits::AxumState;
13use axum::Router;
14use tower_http::{services::ServeDir, trace::TraceLayer};
15
16fn router<S>(scope: &Scope) -> Router<S>
17where
18    S: AxumState,
19{
20    // turn the scope into a path
21    let tgt = scope.as_path();
22
23    Router::new()
24        .merge(serve_dir("/", tgt))
25        .layer(TraceLayer::new_for_http())
26        .with_state(AppState::new())
27}
28
29fn serve_dir<S, P>(path: &str, workdir: P) -> Router<S>
30where
31    P: AsRef<std::path::Path>,
32    S: Clone + Send + Sync + 'static,
33{
34    Router::new().nest_service(path, ServeDir::new(workdir))
35}
36
37#[derive(
38    Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
39)]
40pub struct AppState {}
41
42impl AppState {
43    pub fn new() -> Self {
44        Self {}
45    }
46}
47
48unsafe impl Send for AppState {}
49
50unsafe impl Sync for AppState {}