loc*_*ost 5 express apollo graphql
套餐: apollo-server-express
版本: v2.6.0
问题: CORS 设置未生效。
向 Apollo 报告?:是的,第 3058 期
描述:从我们的 React 客户端,我们开始发送apollographql-client-name和apollographql-client-version标头,以在 Apollo Engine 中更好地了解客户端。
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通过传递cors: true. 出于某种原因,这种变化没有任何区别。我们继续收到上述错误。
const server: ApolloServer = new ApolloServer({
...
...
});
const app: Application = express();
server.applyMiddleware({
app,
cors: true,
path: '/graphql',
});
Run Code Online (Sandbox Code Playgroud)
nginx坐在前面,它确实收到请求并转发到 Apollo Server。cors: true 默认情况下启用一切?cors: {
origin: true,
allowedHeaders: ['Authorization', 'Content-Type', 'apollographql-client-name']
},
Run Code Online (Sandbox Code Playgroud)
欢迎任何意见和建议!
| 归档时间: |
|
| 查看次数: |
850 次 |
| 最近记录: |