将 Apollo Express 服务器部署到 Heroku 时出现问题:"GET query missing."
Problem deploying Apollo Express server to Heroku: "GET query missing."
我使用 Apollo Express 编写了一个简单的 GraphQL 服务器并将其部署到 Heroku。在处理了一些 Procfiles 之类的东西之后,它构建成功了。
当我点击主键时 URL https://limitless-atoll-59109.herokuapp.com 我得到了错误
Cannot GET /
好的,然后我认为 Express 服务器一定只是在寻找 graphql 端点上的获取。但是当我点击 https://limitless-atoll-59109.herokuapp.com/graphql 我得到
GET query missing.
我需要在 url 中包含一个端口吗?我在代码中正确设置了端口
const PORT = process.env.PORT || 4000
app.listen({port: PORT}, () =>
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
);
但我认为在 Heroku 上访问服务器时不需要包含它,对吗?
不管怎样,这是错误日志中的错误
019-05-08T17:07:41.492327+00:00 heroku[router]: at=info method=GET
path="/graphql" host=limitless-atoll-59109.herokuapp.com
request_id=b6171835-aac4-4b45-8a7b-daebbb3167ed fwd="139.47.21.74"
dyno=web.1 connect=0ms service=900ms status=400 bytes=196
protocol=https
感谢您的帮助!
答案是就是想要的/graphql
结尾的url。但是,当您从浏览器中点击 url 时,它会尝试加载 playground,但失败了,因为 playground 在生产环境中默认处于禁用状态。
但是,您可以从您的客户端应用程序针对 url 进行 graphql 调用,它工作正常。
如果您使用的是 apollo 服务器,您可以在生产环境中启用它:
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
});
我使用 Apollo Express 编写了一个简单的 GraphQL 服务器并将其部署到 Heroku。在处理了一些 Procfiles 之类的东西之后,它构建成功了。
当我点击主键时 URL https://limitless-atoll-59109.herokuapp.com 我得到了错误
Cannot GET /
好的,然后我认为 Express 服务器一定只是在寻找 graphql 端点上的获取。但是当我点击 https://limitless-atoll-59109.herokuapp.com/graphql 我得到
GET query missing.
我需要在 url 中包含一个端口吗?我在代码中正确设置了端口
const PORT = process.env.PORT || 4000
app.listen({port: PORT}, () =>
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
);
但我认为在 Heroku 上访问服务器时不需要包含它,对吗?
不管怎样,这是错误日志中的错误
019-05-08T17:07:41.492327+00:00 heroku[router]: at=info method=GET path="/graphql" host=limitless-atoll-59109.herokuapp.com request_id=b6171835-aac4-4b45-8a7b-daebbb3167ed fwd="139.47.21.74" dyno=web.1 connect=0ms service=900ms status=400 bytes=196 protocol=https
感谢您的帮助!
答案是就是想要的/graphql
结尾的url。但是,当您从浏览器中点击 url 时,它会尝试加载 playground,但失败了,因为 playground 在生产环境中默认处于禁用状态。
但是,您可以从您的客户端应用程序针对 url 进行 graphql 调用,它工作正常。
如果您使用的是 apollo 服务器,您可以在生产环境中启用它:
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
});