Debugging a node app on gcloud to fix 500 server error

6.7k Views Asked by At

We've got a hefty little node app and wanted to try out the google cloud deployment suite to get it online, however our deployments are always resulting in a page with a 500 server error.

Normally I'd provide more information, errors, etc, but I was hoping someone more knowledgeable could guide me in where I can hunt down that information. Nothing of note is appearing in the gcloud terminal when we gcloud preview app deploy, just a bunch of preparing and pushing and a final deployed module [default] to ... message. However, navigating to the URL gives us a 500 server error:

Error: Server Error

The server encountered an error and could not complete your request.
Please try again in 30 seconds.

Taking a peek at the response headers doesn't give any more information, so I've poked through the stackdriver/logs, but the only thing there is a bunch of /_ah/background GETs with no sign of any of our requests.

Where can we be looking to start debugging this issue? It's a node app with an node/express backend, react frontend, and webpack builder.

EDIT: Here's a screenshot of the app engine dashboard.

Our app.yaml:

runtime: nodejs
vm: true

skip_files:
  - ^(.*/)?.*/node_modules/.*$

Our package.json:

  "scripts": {
    "test": "karma start",
    "watch": "watch 'npm run test' client/",
    "clean": "rm -rf dist",
    "webpack-prod": "NODE_ENV=production webpack --progress -p",
    "server-prod": "NODE_ENV=production node ./index.js",
    "prestart": "npm run webpack-prod",
    "start": "npm run server-prod",
  },
3

There are 3 best solutions below

2
On BEST ANSWER

In the future, gcloud preview app logs read will get you logs here that will show why the process is crashing (assuming that was the problem). We're working on surfacing these errors as part of the deployment.

0
On

Evidently one issue that can arise with Node apps is that you're not running a production build. I just came to GCP from Heroku, who automatically created production builds for my React app. I was getting 500 errors from GCP with no intelligible information in the logs. I found this GitHub issue, ran npm run build, and changed my app.yaml file to

runtime: nodejs10

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

 - url: /(.*)
   static_files: build/\1
   upload: build/(.*)

and that did the trick. Anyway, I'm just putting this here because app.yaml and your build process may be one cause of mysterious 500 errors.

Edit: just so I don't mislead anyone, if you want to support multiple routes in a React app, you actually need an app.yaml file that looks more like the one in this question (yes, the question; it answers itself).

0
On

Here is the latest command for checking logs on Google Cloud

gcloud app logs read