【问题标题】:Deploy Nuxt.js to Google App Engine Return 502 Bad Gateway将 Nuxt.js 部署到 Google App Engine 返回 502 Bad Gateway
【发布时间】:2018-08-06 04:53:01
【问题描述】:

您好,是否有人尝试将 nuxt 应用程序部署到 Google App Engine。我尝试过 nuxt 常规和 express 模板,它显示 502 Bad Gateway。我不会修改 create-nuxt-app 命令中的任何内容。我的app.yaml 文件包含

runtime: nodejs
env: flex

我的设置有什么问题,或者我需要做一些额外的设置吗?

这是我的package.json

{
  "name": "nuxt-pwa-vuetify-starter",
  "version": "1.0.0",
  "description": "Nuxt.js + PWA + Vuetify.js starter project",
  "author": "Jefry Dewangga <jefrydco@gmail.com>",
  "private": true,
  "homepage": "https://github.com/jefrydco/nuxt-pwa-vuetify-starter#readme",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/jefrydco/nuxt-pwa-vuetify-starter"
  },
  "keywords": [
    "nuxt",
    "nuxt.js",
    "nuxtjs",
    "nuxt pwa",
    "vue",
    "vue.js",
    "vuejs",
    "vue universal",
    "vue ssr",
    "vue pwa",
    "vuetify",
    "vuetify.js",
    "vuetifyjs"
  ],
  "engines": {
    "node": ">=8.0.0",
    "npm": ">=5.0.0"
  },
  "scripts": {
    "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
    "build": "nuxt build",
    "prestart": "npm run build",
    "start": "cross-env NODE_ENV=production node server/index.js",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.0.1",
    "@nuxtjs/browserconfig": "0.0.7",
    "@nuxtjs/component-cache": "^1.1.1",
    "@nuxtjs/dotenv": "^1.1.0",
    "@nuxtjs/google-analytics": "^2.0.2",
    "@nuxtjs/pwa": "^2.0.5",
    "@nuxtjs/sentry": "^1.0.1",
    "@nuxtjs/sitemap": "0.0.3",
    "babel-plugin-transform-imports": "^1.4.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "cross-env": "^5.1.3",
    "express": "^4.16.2",
    "morgan": "^1.9.0",
    "node-sass": "^4.7.2",
    "nodemon": "^1.17.1",
    "nuxt": "^1.3.0",
    "pug": "^2.0.0-rc.4",
    "sass-loader": "^6.0.7",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2",
    "vuetify": "^1.0.3"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.2",
    "eslint": "^4.18.1",
    "eslint-config-standard": "^10.2.1",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-html": "^4.0.2",
    "eslint-plugin-import": "^2.9.0",
    "eslint-plugin-node": "^6.0.1",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1"
  }
}

这是我的应用服务器index.js

const express = require('express')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 8080

app.set('port', port)

// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')

async function start () {
  // Init Nuxt.js
  const nuxt = new Nuxt(config)

  // Build only in dev mode
  if (config.dev) {
    const builder = new Builder(nuxt)
    await builder.build()
  }

  // Give nuxt middleware to express
  app.use(nuxt.render)

  // Listen the server
  app.listen(port, host)
  console.log('Server listening on http://' + host + ':' + port) // eslint-disable-line no-console
}
start()

【问题讨论】:

标签: node.js google-app-engine vue.js nuxt.js


【解决方案1】:

下面对我有用。

package.json

"start": "npm install --save cross-env && nuxt build && cross-env NODE_ENV=production node server/index.js",

在服务和 nuxt 构建之前安装 cross-env 是生产中的必需命令。

另外,我对 server.js 进行了更改

添加健康路线表达:

  app.get('/_ah/health', (req, res) => {
    res.status(200)
    res.send({hello:'world'})
  })

只听端口

// app.listen(host,port) 
app.listen(port)

【讨论】:

  • 你能用完整的工作解决方案链接到一个 github 项目吗?基于github.com/nuxt-community/express-template?我尝试在此问题之上进行更改,但即使这样也不起作用,抛出 [...] + cross-env@5.1.4 删除了 660 个包并在 11.562s 中更新了 10 个包 sh: 1: nuxt:未找到错误发生意外错误:“命令失败。
猜你喜欢
  • 1970-01-01
  • 2014-10-04
  • 2021-03-31
  • 2020-08-27
  • 2021-10-02
  • 1970-01-01
  • 2015-07-25
  • 2020-06-14
  • 2021-02-24
相关资源
最近更新 更多