Skip to main content

cors_allowing

Function cors_allowing 

Source
pub fn cors_allowing<I, S>(origins: I) -> CorsLayer
where I: IntoIterator<Item = S>, S: AsRef<str>,
Expand description

Build a CORS layer that allows the given origins.

Allows the common REST methods (GET, POST, PUT, PATCH, DELETE, OPTIONS), the content-type and authorization request headers, and credentials. Origins that fail to parse as header values are skipped. Requires the cors feature.

ยงExample

use axum::{routing::get, Router};
use axum_api_kit::cors_allowing;

let app: Router = Router::new()
    .route("/", get(|| async { "ok" }))
    .layer(cors_allowing(["https://app.example.com"]));