如何为React应用配置Google App Engine nodejs8标准环境?

时间:2018-09-06 02:55:32

标签: node.js reactjs google-app-engine google-cloud-platform

我为Google App Engine使用React和Node.js 8开发了一个简单的应用程序。它在灵活环境中可以正常工作,但是如果我尝试在标准环境中部署它,则会收到“ GET / HTTP / 1.1” 500错误。除此之外,我找不到更多的问题信息。

如何配置它以使其在标准环境中工作?

app.standard.yaml

runtime: nodejs8

handlers:
  - url: /
    script: src/index.js
  - url: /src
    script: index.js

package.json

{
  "name": "eventpub",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "node": "8.x.x"
  },
  "dependencies": {
    "node-pre-gyp": "^0.11.0",
    "npm": "^5.6.0",
    "react": "^16.4.2",
    "react-collapsible": "^2.3.1",
    "react-dom": "^16.4.2",
    "react-json-viewer": "^1.7.1",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

项目文件夹结构

node_modules
public
- public/index.html
- public/manifest.json
src
- src/App.css
- src/App.js
- src/App.test.js
- src/index.css
- src/index.js
- src/registerServiceWorker.js
.gcloudignore
.gitignore
app.flexible.yaml
app.standard.yaml
package.json
package-lock.json
README.md

2 个答案:

答案 0 :(得分:0)

在我看来,您遇到的问题是由于https://cloud.google.com/appengine/docs/standard/nodejs/runtime#dependencies

中提到的Node.js的App Engine Standard仍处于测试阶段

答案 1 :(得分:0)

我通过首先构建react应用(npm run build),将已经构建的版本部署到Google Cloud并在app.yaml中添加已构建应用的处理程序来解决了这个问题。

handlers:
- url: /
  static_files: build/index.html
  upload: build/index.html
- url: /
  static_dir: build