【发布时间】:2021-07-05 10:33:18
【问题描述】:
Apollo 服务器只是忽略我的 CORS 层并应用它自己的选项。
尽管使用选项反映使用以下代码设置 CORS 中间件:
var corsOptions = {
origin: true, //This will just copy the request origin and put it in response
optionsSuccessStatus: 200,
credentials: true,
};
app.use(cors(corsOptions));
const apolloServer = new ApolloServer({ schema, context , playground: true});
await apolloServer.start();
//Integrate with express
apolloServer.applyMiddleware({app, path: '/api/graphql', cors: corsOptions});
Apollo 服务器只是忽略了我的 CORS 层并返回 'Access-Control-Allow-Origin' : "\*",因此我收到了 CORS 错误,因为:
当请求的凭据模式为“包含”时,响应中的“Access-Control-Allow-Origin”标头的值不能是通配符“*”。
【问题讨论】:
-
如果目标是让其他帖子更易于搜索,您可以建议修改其标题,而不是写一个全新的问题。
标签: node.js express cors apollo-server