Debugging a node app on gcloud to fix 500 server error
Asked Answered
C

3

5

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",
  },
Calv answered 13/5, 2016 at 19:26 Comment(5)
Mind sharing a screenshot of you App Engine Dashboard?Sailesh
No problem, do you mean this? i.imgur.com/fVxeT1k.png?1Calv
First of all, test it on 1 instance rather than 20. :D Next change your server-pod task to be "server-prod": "NODE_ENV=production node index.js", and it should work.Ladysmith
@komali_2 , is your issue resolved?Accord
@kamran I have solved the problem we were having with our server (compiling was taking too long so the process was exited), however, we found this out by sheer luck. I'm still not sure the best way to debug a node app on gcloud.Calv
C
3

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.

Crosspollination answered 24/6, 2016 at 16:27 Comment(2)
Running your command yeilds ´ERROR: (gcloud) Invalid choice: 'preview'.´Cis
You can drop the 'preview' now :)Crosspollination
F
3

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).

Fisherman answered 6/7, 2019 at 1:51 Comment(0)
L
2

Here is the latest command for checking logs on Google Cloud

gcloud app logs read
Lily answered 28/4, 2020 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.