Skip to main content

quorum_private/routes/
route.rs

1//! Routes for the public Quorum server.
2
3use axum::{
4    Router,
5    routing::{get, post},
6};
7use http::header::{HeaderName, HeaderValue};
8use quorum_core::db::DB;
9use quorum_core::routes::{echo::echo, health::health};
10use tower::ServiceBuilder;
11use tower_http::cors::{Any, CorsLayer};
12use tower_http::set_header::SetResponseHeaderLayer;
13
14pub fn create_router(db: DB) -> Router {
15    let cors = CorsLayer::new()
16        .allow_origin(Any)
17        .allow_methods(Any)
18        .allow_headers(Any);
19
20    let security_headers = ServiceBuilder::new()
21        .layer(SetResponseHeaderLayer::if_not_present(
22            HeaderName::from_static("x-frame-options"),
23            HeaderValue::from_static("DENY"),
24        ))
25        .layer(SetResponseHeaderLayer::if_not_present(
26            HeaderName::from_static("strict-transport-security"),
27            HeaderValue::from_static("max-age=31536000; includeSubDomains; preload"),
28        ))
29        .layer(SetResponseHeaderLayer::if_not_present(
30            HeaderName::from_static("x-content-type-options"),
31            HeaderValue::from_static("nosniff"),
32        ));
33
34    Router::new()
35        .route("/", get(|| async { "Quorum public server is running" }))
36        .route("/health", get(health))
37        .route("/echo", post(echo))
38        .layer(cors)
39        .layer(security_headers)
40        .with_state(db)
41}