github - 在 GitHub Codespaces 上运行的 Apollo Server 中的“预检响应不成功”
问题描述
我遵循了Github Codespace中的 Apollo Getting Started示例。
启动服务器后,我看到错误:
{
"error": "Preflight response is not successful"
}
要重现的示例 repo 在这里:https ://github.com/aniskny/codespaces-test
我尝试了各种选项,cors
但没有奏效:
...
new ApolloServer({ typeDefs, resolvers
cors: {
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
}
});
...
解决方案
我有同样的问题。事实证明,Playground 没有转发您的 Github 凭据。请注意,如果您在隐身窗口中访问预览 URL,您将被重定向到 Github 登录屏幕。解决方案是更改 Playground 设置,以便在 GraphQL 请求中发送您的凭据。
- 点击右上角,点击齿轮图标(设置)
- 更改以下内容
- "request.credentials": "omit",
+ "request.credentials": "same-origin",
推荐阅读
- c# - 如何在生产中使用迁移,但不能在测试中使用?
- ios - 导航栏存储弹出视图控制器的属性
- html - NodeJS 使用元素树深度抓取数据
- jquery - 如何在 jQuery 中获取音频文件的 RMS 值
- apache-spark - 如何更改 spark-submit 控制台输出中的日志级别?
- python - 关联规则挖掘算法
- elixir - 如何使用 Elixir 在 Hound 中实现 Chromedriver
- vue.js - 将 vue 组件编译成“普通”网页的一些指针
- javascript - 如何在摩纳哥编辑器中调用`setValue()`后立即格式化代码?
- mysql - 在 Heroku 应用程序中连接到 MySQL 数据库时出现类型错误