【发布时间】:2020-08-18 13:39:56
【问题描述】:
我正在尝试将使用 CRA 和 Typescript 创建的应用程序部署到 Google Cloud App Engine 服务中,但是,由于某种原因,appspot 链接会一直加载直到出现 502 Bad Gateway(有时会出现错误,通常它只是一直在加载..)
我已经检查了几个教程和问题,但都没有成功。
- Deploy create-react-app on Google App Engine
- https://medium.com/tech-tajawal/deploying-react-app-to-google-app-engine-a6ea0d5af132
app.yaml 如下:
env: flex
runtime: nodejs
handlers:
- url: /static/js/(.*)
static_files: build/static/js/\1
upload: build/static/js/(.*)
- url: /static/css/(.*)
static_files: build/static/css/\1
upload: build/static/css/(.*)
- url: /static/media/(.*)
static_files: build/static/media/\1
upload: build/static/media/(.*)
- url: /(.*\.(json|ico))$
static_files: build/\1
upload: build/.*\.(json|ico)$
- url: /
static_files: build/index.html
upload: build/index.html
- url: /.*
static_files: build/index.html
upload: build/index.html
env_variables:
REACT_APP_DEV_API_URL: "......"
REACT_APP_MAP_API_KEY: "........"
# [END app_yaml]
Logs of the app engine(好像每次打开页面都会调用'npm run start'命令)
当然,我的应用程序在开发模式下运行良好,而且在deployment logs 中似乎也没有任何问题。 如果有人以前遇到过这个问题,请告诉我如何解决。提前致谢。
package.json:
{
"name": "testing-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/google-map-react": "^1.1.5",
"@types/jest": "^24.0.0",
"@types/lodash": "^4.14.149",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-helmet": "^5.0.15",
"@types/react-router-dom": "^5.1.3",
"@types/styled-components": "^5.0.0",
"@types/swiper": "^5.2.1",
"axios": "^0.19.2",
"google-map-react": "^1.1.6",
"lodash.differenceby": "^4.8.0",
"lodash.throttle": "^4.1.1",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-circular-progressbar": "^2.0.3",
"react-dom": "^16.12.0",
"react-id-swiper": "^3.0.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"semantic-ui-react": "^0.88.2",
"styled-components": "^5.0.1",
"swiper": "^5.3.6",
"typescript": "~3.7.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.14.0",
"@typescript-eslint/parser": "^2.14.0",
"cross-env": "^6.0.3",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-config-react-app": "^5.1.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^2.3.0",
"gh-pages": "^2.2.0",
"jest": "^24.9.0",
"lint-staged": "^9.5.0",
"pre-commit": "^1.2.2",
"prettier": "^1.19.1"
},
"lint-staged": {
"*.js": [
"npm run lint:eslint:fix",
"git add --force"
],
"*.json": [
"prettier --write",
"git add --force"
]
},
"pre-commit": "lint:staged",
"resolutions": {
"serialize-javascript": "^2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:clean": "rimraf ./build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint:staged": "lint-staged",
"lint:eslint": "eslint --ignore-path .gitignore",
"lint:eslint:fix": "eslint --ignore-path .gitignore --fix",
"prettify": "prettier --write"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
项目结构是typical CRA with containers-components(忽略我在拍摄照片时使用 Gcloud 运行另一种方式测试的 nginx.conf 和 dockerfile)
编辑:添加项目结构和package.json
【问题讨论】:
-
你能分享你的 Dockerfile 吗?谢谢
-
您好,感谢您的回答。我没有使用 dockerfile 部署它。如教程中所述,我只使用 gcloud app run deploy 。我看到了另一种使用 Gcloud run 的方法,但我想知道为什么它不适用于 App Engine。
-
你能分享你的 package.json 文件吗?否则您能否分享您的应用程序文件的结构?谢谢
-
通过App Engine Flexible Official Documentation,你必须使用 gcloud app delpoy 命令,你能解释一下你为什么运行 gcloud app run deploy 命令吗?
-
对不起,我没有解释清楚。我说的是那个命令(gcloud app deploy)。我将在今天晚些时候更新 package.json 和结构。谢谢
标签: reactjs google-app-engine google-cloud-platform create-react-app