pub mod routes;
pub mod state;
pub mod tunnel;
use axum::{
http::{header, HeaderValue},
Router,
};
use std::sync::Arc;
use tower_http::cors::{Any, CorsLayer};
use tower_http::set_header::SetResponseHeaderLayer;
use tower_http::trace::TraceLayer;
pub use state::{AuthRateLimitConfig, AuthResult, RelayConfig, RelayState, TokenError, TunnelClaims};
pub fn create_relay_app(state: Arc<RelayState>) -> Router {
let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(Any);
Router::new()
.merge(routes::routes())
.layer(TraceLayer::new_for_http())
.layer(cors)
.layer(security_headers_layer())
.with_state(state)
}
fn security_headers_layer() -> tower::ServiceBuilder<
tower::layer::util::Stack<
SetResponseHeaderLayer<HeaderValue>,
tower::layer::util::Stack<
SetResponseHeaderLayer<HeaderValue>,
tower::layer::util::Stack<
SetResponseHeaderLayer<HeaderValue>,
tower::layer::util::Stack<
SetResponseHeaderLayer<HeaderValue>,
tower::layer::util::Stack<
SetResponseHeaderLayer<HeaderValue>,
tower::layer::util::Identity,
>,
>,
>,
>,
>,
> {
tower::ServiceBuilder::new()
.layer(SetResponseHeaderLayer::overriding(
header::STRICT_TRANSPORT_SECURITY,
HeaderValue::from_static("max-age=31536000; includeSubDomains; preload"),
))
.layer(SetResponseHeaderLayer::overriding(
header::X_FRAME_OPTIONS,
HeaderValue::from_static("DENY"),
))
.layer(SetResponseHeaderLayer::overriding(
header::X_CONTENT_TYPE_OPTIONS,
HeaderValue::from_static("nosniff"),
))
.layer(SetResponseHeaderLayer::overriding(
header::X_XSS_PROTECTION,
HeaderValue::from_static("1; mode=block"),
))
.layer(SetResponseHeaderLayer::overriding(
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'self'; frame-ancestors 'none'; form-action 'self'"),
))
}