如何在 Zeit Now 上使用 GraphQL 后端部署 Next.js? [英] How to deploy Next.js with GraphQL backend on Zeit Now?

查看:27
本文介绍了如何在 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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆