简体   繁体   English

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

[英]How to configure a Google App Engine nodejs8 Standard Environment for React app?

I have developed a simple app using React and Node.js 8 for Google App Engine. 我使用React和Node.js 8 for Google App Engine开发了一个简单的应用程序。 It works fine in the Flexible Environment, but if I try to deploy it on the Standard Environment, I am getting "GET / HTTP/1.1" 500 errors. 它在灵活环境中可以正常工作,但是如果我尝试在标准环境中部署它,则会收到“ GET / HTTP / 1.1” 500错误。 I can't find any more information on what is going wrong beyond that. 除此以外,我找不到更多有关发生问题的信息。

How can I configure it so that it will work in the standard environment? 如何配置它使其在标准环境中运行?

app.standard.yaml app.standard.yaml

runtime: nodejs8

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

package.json 的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"
  }
}

project folder structure 项目文件夹结构

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

在我看来,您遇到的问题是由于https://cloud.google.com/appengine/docs/standard/nodejs/runtime#dependencies所述的Node.js的App Engine Standard仍处于测试阶段

I solved the issue by building the react app first (npm run build), deploying the already built version to google cloud, and adding handlers for the built app in app.yaml. 我通过首先构建react应用(npm run build),将已经构建的版本部署到google cloud以及在app.yaml中添加已构建应用的处理程序来解决了该问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用NodeJ运行App Engine标准环境 - Run App Engine standard environment with NodeJs Google App Engine 标准上的 Nodejs 版本 - Nodejs version on Google App Engine standard 如何在 App Engine Nodejs Standard 上访问内存缓存 - How to access memcache on App Engine Nodejs Standard 如何在 Google App Engine 标准环境中使用 Google Cloud Build 或其他方法设置环境变量? - How to set environment variables using Google Cloud Build or other method in Google App Engine Standard Environment? 为什么nodejs实例无法在google app engine标准环境下启动成功? - Why couldn't nodejs instance start successfully in google app engine standard environment? 将节点应用程序部署到Google App Engine标准环境 - Deploy node application to Google App Engine standard environment Google App Engine灵活环境中的多个NodeJS服务/模块 - Multiple NodeJS Services/Modules on Google App Engine Flexible Environment 如何在Google App Engine中为节点反应项目配置app.yaml文件 - How to configure app.yaml file for node react project in google app engine Google App Engine 和 Travis CI 上的 NodeJS 环境变量 - NodeJS environment variables on Google App Engine and Travis CI 如何为部署在 Google App Engine node.js flex 环境中的 React 应用程序强制使用 https? - How to force https for a React app deployed on Google App Engine node.js flex environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM