如何在 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