【发布时间】:2020-07-12 08:06:46
【问题描述】:
所以我的 Apollo graphql 服务器在开发中运行良好。我刚刚将我的项目部署到 Heroku,现在在进行任何查询时都会收到 503 错误。
我能够进入 graphiql 沙箱,但这些响应返回为:
SyntaxError: Unexpected token < in JSON at position 0
我正在为我的服务器使用 express,代码如下所示:
app.use(cors());
app.use(
'/graphql',
graphqlHTTP({
schema: pgSchema,
graphiql: true
})
);
app.use(express.static('../public'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../public', 'index.html'));
});
这是我在 React 项目中连接我的 Apollo 客户端的地方:
const client = new ApolloClient({
uri: '/graphql'
});
function App() {
return (
<ApolloProvider client={client}>
<Router>
<Route exact path='/' component={Login} />
<Route exact path='/home' component={Home} />
</Router>
</ApolloProvider>
);
}
这是我从 graphql 获得的 heroku 日志:
2020-03-31T16:41:23.780542+00:00 heroku[router]: at=info method=POST path="/graphql" host=damp-ravine-76294.herokuapp.com request_id=a9e695db-63eb-476a-950f-a5d6561ff85f fwd="76.116.11.127" dyno=web.1 connect=1ms service=21ms status=200 bytes=21933 protocol=https
2020-03-31T16:45:50.392011+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/graphql" host=damp-ravine-76294.herokuapp.com request_id=650a1d7d-7f9e-4c66-8a5d-000fc60ed29a fwd="76.116.11.127" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
如果您有任何想法,请告诉我。谢谢!
【问题讨论】: