0

我正在使用 nginx 运行带有 wp-graphql 插件的 wordpress 站点。

我的 nginx 配置的相关位如下所示:

location /graphql {
    add_header Access-Control-Allow-Origin "http://localhost:8080";
    try_files $uri $uri/ /index.php$is_args$args;
}

我使用 Apollo 作为 graphql 客户端并且我已经设置了credentials: "include". 但是当我这样做时,我在进行任何 graphql 查询时突然出现这个错误。

Access to fetch at 'https://example.com/graphql' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

如果我删除credentials: "include",那么查询将起作用,但我的任何 cookie 都没有附加到请求中!

我很困惑,因为该错误似乎表明 Access-Control-Allow-Origin 标头不应该是“*”,但正如您从我的 nginx 配置中看到的那样,显然不是!

4

0 回答 0