quarkus:受到CORS政策的禁止

时间:2019-07-09 19:37:06

标签: cors quarkus

尽管我配置了属性文件,但仍然收到错误:

blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  

我还创建了 @Provider 扩展了 ContainerRequestFilter ,但是它   永远不会到达那里

application.properties

# Configuration file
quarkus.http.port=9090
quarkus.http.cors=true
quarkus.http.origins=http://localhost:4200, localhost:9090
quarkus.http.headers=accept, authorization, content-type, x-requested-with
quarkus.http.methods=GET, OPTIONS

已编辑

17:11:09 WARN  [io.qu.config]] (build-3) Unrecognized configuration key "quarkus.http.methods" provided
17:11:09 WARN  [io.qu.config]] (build-3) Unrecognized configuration key "quarkus.http.headers" provided
17:11:09 WARN  [io.qu.config]] (build-3) Unrecognized configuration key "quarkus.http.origins" provided

1 个答案:

答案 0 :(得分:4)

警告是一个很好的指示。

您的配置不正确。

应该是这样的:

quarkus.http.cors.origins=http://localhost:4200,http://localhost:9090
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
quarkus.http.cors.methods=GET, OPTIONS

带有cors前缀。

我们现在没有适当的文档,所以最好参考https://github.com/quarkusio/quarkus/blob/master/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/filters/CORSConfig.java

我打开https://github.com/quarkusio/quarkus/issues/3156来跟踪文档问题。