【发布时间】:2019-11-27 23:26:14
【问题描述】:
包: apollo-server-express
版本: v2.6.0
问题: CORS 设置未生效。
向 Apollo 报告? 是的,Issue 3058
描述:从我们的 react 客户端,我们开始在 Apollo 引擎中为 better client awareness 发送 apollographql-client-name 和 apollographql-client-version 标头。
Access to fetch at 'https://something.com/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field apollographql-client-name is not allowed by Access-Control-Allow-Headers in preflight response.
我们收到上述CORS 错误。我们通过快速中间件通过cors: true 在 Apollo Server 上启用了cors。出于某种原因,这种变化没有任何区别。我们继续收到上述错误。
const server: ApolloServer = new ApolloServer({
...
...
});
const app: Application = express();
server.applyMiddleware({
app,
cors: true,
path: '/graphql',
});
- 我们有
nginx坐在前面,它确实接收请求并转发到 Apollo 服务器。 -
cors: true默认启用一切? - 我们尝试过非常具体,但这也无济于事。
cors: {
origin: true,
allowedHeaders: ['Authorization', 'Content-Type', 'apollographql-client-name']
},
欢迎任何意见和建议!
【问题讨论】: