use axum::http::{HeaderName, Method};
use std::time::Duration;
use tower_http::cors::CorsLayer;
pub fn create_cors_layer(allowed_origin: axum::http::HeaderValue) -> CorsLayer {
CorsLayer::new()
.allow_origin(allowed_origin)
.allow_methods([
Method::GET,
Method::POST,
Method::PUT,
Method::DELETE,
Method::PATCH,
Method::OPTIONS,
])
.allow_headers([
axum::http::header::CONTENT_TYPE,
axum::http::header::AUTHORIZATION,
axum::http::header::ACCEPT,
axum::http::header::COOKIE,
HeaderName::from_static("x-csrf-token"),
])
.allow_credentials(true)
.max_age(Duration::from_secs(3600))
}
pub fn create_permissive_cors_layer() -> CorsLayer {
CorsLayer::permissive()
}