首页 > 解决方案 > 仅通过 https 进行长查询时出现 502 错误

问题描述

我的 gql 服务器上有一个相当长的查询,解析器调用了一个 grpc 方法。当我在本地运行它时它可以工作,但是当我对我们的开发部署(https)进行查询时,请求会返回

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>502 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>

还有其他可以通过 https 调用的 grpc 调用。所以我认为那里没有任何问题..

在 gcp 日志中,我实际上可以看到解析器记录的结果。尽管在浏览器中它是一个 502 错误。

我的解析器

train: async (parent, args) => {
      const { projectId, yml } = args
      let result = await nluTrain(projectId, yml);
      return { done:result }
    }

我的服务器

const server = new ApolloServer({
  typeDefs: schema,
  resolvers,
  context: async ({ req, connection}) => {
    if(req){
      return {
        req,
      };
    }
  },
});


server.applyMiddleware({ app, path: '/graphql' });
const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen({ port: 8001 }, () => {
  console.log('Apollo Server on http://localhost:8001/graphql');
});

标签: graphqlgoogle-kubernetes-enginegrpcapollo-server

解决方案


推荐阅读