本文介绍了如何在Zeit Now上使用GraphQL后端部署Next.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在本地主机上运行良好的Next.js/Express/Apollo GraphQL应用程序.

I have an Next.js/Express/Apollo GraphQL app running fine on localhost.

我尝试将其部署在Zeit Now上,并且Next.js部分工作正常,但是GraphQL后端失败,因为/graphql路由返回:

I try to deploy it on Zeit Now, and the Next.js part works fine, but the GraphQL backend fails because /graphql route returns:

502: An error occurred with your deployment
Code: NO_STATUS_CODE_FROM_LAMBDA

我的now.json看起来像:

{
  "version": 2,
  "builds": [
    { "src": "next.config.js", "use": "@now/next" },
    { "src": "server/server.js", "use": "@now/node" }
  ],
  "routes": [
    { "src": "/api/(.*)", "dest": "server/server.js" },
    { "src": "/graphql", "dest": "server/server.js" }
  ]
}

建议?

推荐答案

下面是在Zeit Now(作为无服务器功能/lambda)和Heroku(对于Express服务器)上运行的Next.js/Apollo GraphQL的完整示例:

Here’s a complete example of Next.js/Apollo GraphQL running both on Zeit Now (as serverless function/lambda) and Heroku (with an Express server):

https://github.com/tomsoderlund/nextjs- pwa-graphql-sql-boilerplate

https://github.com/tomsoderlund/nextjs-pwa-graphql-sql-boilerplate

这篇关于如何在Zeit Now上使用GraphQL后端部署Next.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:48