summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: b8f322be77fe6af65b0be31232a3bba2e88951a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use tower_http::trace::TraceLayer;

pub use error::{Error, Result};

pub mod api;
pub mod auth;
pub mod error;
pub mod state;
pub mod utils;

pub fn router() -> axum::Router<state::AppState> {
    axum::Router::new()
        .nest("/api", api::router())
        .nest("/auth", auth::router())
        .layer(TraceLayer::new_for_http())
}

#[cfg(test)]
pub(crate) mod tests {
    use std::sync::Once;

    use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

    pub type TestResult<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;

    pub const JWT_SECRET: &str = "test-jwt-secret-token";

    static INIT: Once = Once::new();

    pub fn setup_test_env() {
        INIT.call_once(|| {
            tracing_subscriber::registry()
                .with(tracing_subscriber::EnvFilter::from_default_env())
                .with(tracing_subscriber::fmt::layer().with_test_writer())
                .init();

            std::env::set_var("JWT_SECRET", JWT_SECRET);
        });
    }
}