【发布时间】:2020-07-10 09:40:59
【问题描述】:
我正在尝试部署具有服务器端目录和客户端的项目。我也在使用pm2来启动双方的服务...这是文件夹结构目录:
MyProject
+-- server
| --- app.js
| --- app.yaml
| --- package.json
+-- client
| +-- build
| --- index.html
| --- package.json
|....
--- .gitignore
package.json 的服务器脚本
{...
"scripts": {
"client": "npm start --prefix ../client",
"deploy": "gcloud app deploy app.yaml",
"dev": "concurrently \"npm run build\" \"npm run client\"",
"start": "pm2 start app.config.json"
},
...
}
app.config.json 文件,因为我使用的是 pm2:
{
"apps" : [
{
"name" : "clientApp",
"script": "node",
"args" : "../client/scripts/start.js"
},
{
"name" : "serverApp",
"script" : "node",
"args": "./bin/www"
}
]
}
app.js
app.use(express.static(path.join(__dirname, '../client/build')));
这是服务器的设置。现在这里是客户端。 包.json
"scripts": {
"start": "pm2 start scripts/start.js --name clientApp",
"build": "node scripts/build.js",
"serve": "serve -s build -l 8080",
},
"proxy": "http://localhost:5000",
最重要的是,app.yaml:
runtime: nodejs
env: flex
handlers:
- url: /api/.*
script: auto
- url: /
static_files: client/build/index.html
upload: client/build/index.html
- url: /
static_dir: client/build
- url: /static
static_dir: client/build/static
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
manual_scaling:
instances: 1
resources:
cpu: 2
memory_gb: 8.0
disk_size_gb: 20
我得到的错误是应用程序启动错误!代码:APP_CONTAINER_CRASHED,为什么会这样?我是否在 app.yaml 中错误地获取了客户端目录???
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error! Code: APP_CONTAINER_CRASHED
yarn run v1.17.3
$ pm2 start app.config.json
...
...
...
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications clientApp, serverApp not running, starting...
[PM2] App [clientApp] launched (1 instances)
[PM2] App [serverApp] launched (1 instances)
┌─────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ \u21ba │ status │ cpu │ mem │ user │ watching │
├─────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ clientApp │ default │ N/A │ fork │ 50 │ 0s │ 0 │ online │ 0% │ 28.2mb │ root │ disabled │
│ 1 │ serverApp │ default │ N/A │ fork │ 56 │ 0s │ 0 │ online │ 0% │ 25.4mb │ root │ disabled │
└─────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Done in 2.05s.
error Command failed with exit code 1.
【问题讨论】:
标签: node.js reactjs google-app-engine deployment pm2