warp::filters::cors

Function cors

source
pub fn cors() -> Builder
Expand description

Create a wrapping Filter that exposes CORS behavior for a wrapped filter.

ยงExample

use warp::Filter;

let cors = warp::cors()
    .allow_origin("https://hyper.rs")
    .allow_methods(vec!["GET", "POST", "DELETE"]);

let route = warp::any()
    .map(warp::reply)
    .with(cors);

If you want to allow any route:

use warp::Filter;
let cors = warp::cors()
    .allow_any_origin();

You can find more usage examples here.