【问题标题】:How to configure a Google App Engine nodejs8 Standard Environment for React app?如何为 React 应用配置 Google App Engine nodejs8 标准环境?
【发布时间】:2019-02-11 05:34:23
【问题描述】:

我使用 React 和 Node.js 8 为 Google App Engine 开发了一个简单的应用程序。它在灵活环境中运行良好,但如果我尝试在标准环境中部署它,我会收到“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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      在我看来,您遇到的问题似乎是由于在 https://cloud.google.com/appengine/docs/standard/nodejs/runtime#dependencies 中提到的 App Engine Standard for Nodejs 仍处于测试阶段

      【讨论】:

        猜你喜欢
        • 2018-03-12
        • 2018-07-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 1970-01-01
        • 2020-07-24
        • 2020-11-23
        • 2017-09-22
        相关资源
        最近更新 更多