Pat*_*ors 1 cors express reactjs graphql
I'm running a react dev server on http://localhost:3000 and an express server on http://localhost:8080 and am using an Apollo Client to query the server. To enable session data to be passed from client to server I have added the credentials: "include" parameter when initializing the Apollo Client.
I've added the following line in my express server (before the routes are defined) to configure cors:
app.use(cors({ credentials: true, origin: "http://localhost:3000" }));
However, when executing queries, the following error is thrown:
Access to fetch at 'http://localhost:8080/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: 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'.
Run Code Online (Sandbox Code Playgroud)
Why is the header response showing up as *? Am I configuring CORs incorrectly or am I missing something else?
我在这里遇到的问题是,尽管为 express 启用了 CORS:
app.use(cors({ credentials: true, origin: "http://localhost:3000" }));
Run Code Online (Sandbox Code Playgroud)
GraphQL 中间件覆盖了设置。cors: false如果使用 Apollo Server 和相关的中间件,请确保传递如下所示的参数。
gqlServer.applyMiddleware({ app, path: "/graphql", cors: false });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3498 次 |
| 最近记录: |