heroku - 向我的 graphql API 发起查询时出现网络错误
问题描述
这是我在进行查询时收到的错误消息:
[Network error]: ServerParseError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
当将我的 ApolloClient 的 uri 设置为http://localhost:4000/graphql
并在本地运行服务器时,查询在本地运行良好。
但是,如果我将服务器部署到 heroku,然后将客户端的 uri 设置为https://my-app.herokuapp.com/
它不起作用,我会收到上面的错误消息。网络选项卡向我的 heroku 应用程序的 POST 请求显示 404,“无法 POST”
heroku 日志在推送时没有显示错误。
知道我在这里缺少什么吗?我检查了所有我能找到的教程,我没有发现任何明显的缺失。
这是我的客户要求:
const client = new ApolloClient({
uri: 'https://my-app.herokuapp.com/',
headers: {
authorization: "Bearer API_KEY",
'content-type': 'application/json'
}
});
解决方案
URI不应该是uri: https://my-app.herokuapp.com/graphql
吗?由于您的 localhost 端点是/graphql
.
希望能帮助到你 :)
推荐阅读
- python - 选择一个文本字符串
- javascript - 如何将带有内联文本样式的 JSON 转换为 html 文本样式?
- apache-spark - 如何检查 kubernetes 上 spark 的错误原因?
- python - 如何使用 Python (Selenium) 抓取画布元素
- javascript - 使用单选按钮一次将函数应用于单个 div
- javascript - jquery如何获取动态创建的每一行的索引
- c++ - 因超时而终止:优化的范围在哪里?
- swift - 流式传输显示、转换它并在窗口中显示它?
- list - 连续流列出,没有重复
- javascript - 希望构建一个正则表达式,以按顺序查找由不同特定长度的空格分隔的 3 个单词