pzzld-server 0.0.2

A production ready server optimized for WASM applications
Documentation
/*
    Appellation: serve <module>
    Contrib: FL03 <jo3mccain@icloud.com>
*/
#[doc(inline)]
pub use self::{actor::Server, context::ServerContext};

mod actor;
mod context;

use crate::config::Scope;
use crate::traits::AxumState;
use axum::Router;
use tower_http::{services::ServeDir, trace::TraceLayer};

fn router<S>(scope: &Scope) -> Router<S>
where
    S: AxumState,
{
    // turn the scope into a path
    let tgt = scope.as_path();

    Router::new()
        .merge(serve_dir("/", tgt))
        .layer(TraceLayer::new_for_http())
        .with_state(AppState::new())
}

fn serve_dir<S, P>(path: &str, workdir: P) -> Router<S>
where
    P: AsRef<std::path::Path>,
    S: Clone + Send + Sync + 'static,
{
    Router::new().nest_service(path, ServeDir::new(workdir))
}

#[derive(
    Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
)]
pub struct AppState {}

impl AppState {
    pub fn new() -> Self {
        Self {}
    }
}

unsafe impl Send for AppState {}

unsafe impl Sync for AppState {}