我正在使用actix-web构建一个REST API。我该如何配置CORS以接受来自任何来源的请求?
上述代码在Web上的localhost:8081上运行正常,但在0.0.0.0:8081或127.0.0.1:8081上无法运行。我尝试使用"*"来允许所有,但没有起作用。我该如何允许所有,或者至少允许一个特定的来源,然后传递多个URL?
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)
上述代码在Web上的localhost:8081上运行正常,但在0.0.0.0:8081或127.0.0.1:8081上无法运行。我尝试使用"*"来允许所有,但没有起作用。我该如何允许所有,或者至少允许一个特定的来源,然后传递多个URL?
allowed_origin
链式调用。 - estinnew
的函数或关联项,用于结构体Cors
。 - Evan CarrollCors :: permissive()
。 - tonayy