Function cors

Source
pub fn cors(config: CorsConfig<'_>) -> CorsLayer
Expand description

CORS layer

This function creates a CORS layer for Axum with the specified configuration.

ยงExample

use axum::http::{header, HeaderName, HeaderValue, Method};
use api_tools::server::axum::layers::cors::{cors, CorsConfig};

let cors_config = CorsConfig {
    allow_origin: "*",
    allow_methods: vec![Method::GET, Method::POST, Method::PUT, Method::PATCH, Method::DELETE],
    allow_headers: vec![header::AUTHORIZATION, header::ACCEPT, header::CONTENT_TYPE, header::ORIGIN],
};

let layer = cors(cors_config);