【发布时间】:2019-12-16 22:20:09
【问题描述】:
我正在使用 actix-web 构建一个 REST API。如何配置 CORS 以接受来自任何来源的请求?
Cors::new() // <- Construct CORS middleware builder
.allowed_origin("localhost:8081")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE)
.max_age(3600)
上面的代码在localhost:8081 的网络上工作,但不是来自0.0.0.0:8081 或127.0.0.1:8081。我尝试"*" 允许所有人,但它不起作用。如何允许所有,或至少允许特定来源,然后传递多个 URL?
【问题讨论】:
标签: rust cors rust-actix actix-web