I'm trying to deploy my project which has a server-side directory and a client-side. I'm also using pm2 to boot up the services for both sides... Here is the folder structure directory:
MyProject
+-- server
| --- app.js
| --- app.yaml
| --- package.json
+-- client
| +-- build
| --- index.html
| --- package.json
|....
--- .gitignore
Server script of 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 file because I'm using 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')));
This is the setup for the Server. Now here is the Client side. package.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",
Most importantly, the 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
The error I'm getting is Application startup error! Code: APP_CONTAINER_CRASHED, why is this happening? Did i source the client side directory incorrectly in the 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.