我正在使用 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
or 127.0.0.1:8081
。我试过"*"
允许所有,但它不起作用。如何允许所有或至少允许特定来源,然后传递多个 URL?
从...开始actix-cors = "0.5.0"
, 您可以使用:
Cors::permissive()
但是,他们建议不要在生产中使用它:https://docs.rs/actix-cors/latest/actix_cors/struct.Cors.html#method.permissive https://docs.rs/actix-cors/latest/actix_cors/struct.Cors.html#method.permissive
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)