Saturday 12 December 2020

Server error 500 when deploying NodeJS Express app on GCP App Engine

I'm trying to deploy a NodeJS app on gcloud that runs my express api. When I run npm start locally I get this message:

>npm start

> my_api@1.0.0 start E:\My_Project\My_API
> node index.js

Running API on port 8080
Connected to DB!

So I created an app.yaml file with the following properties:

runtime: nodejs12
entrypoint: npm start

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

Then I run gcloud app deploy, and everything is deployed properly to the correct project with no errors. But when I go to the base url, I get:

Error: Server Error

The server encountered an error and could not complete your request.

Please try again in 30 seconds.

So I checked the logs with gcloud app logs tail -s default, and I'm noticing the app keeps restarting over and over endlessly:

2020-12-08 00:10:21 default[...]  > node index.js
2020-12-08 00:10:21 default[...]
2020-12-08 00:10:21 default[...]  Running API on port 8081
2020-12-08 00:10:29 default[...]  "GET /_ah/start HTTP/1.1" 302
2020-12-08 00:10:31 default[...]
2020-12-08 00:10:31 default[...]  > my_api@1.0.0 start /workspace
2020-12-08 00:10:31 default[...]  > node index.js
2020-12-08 00:10:31 default[...]
2020-12-08 00:10:31 default[...]  Running API on port 8081
2020-12-08 00:10:41 default[...]  "GET /_ah/start HTTP/1.1" 302
2020-12-08 00:10:43 default[...]
2020-12-08 00:10:43 default[...]  > my_api@1.0.0 start /workspace
2020-12-08 00:10:43 default[...]  > node index.js
2020-12-08 00:10:43 default[...]
2020-12-08 00:10:43 default[...]  Running API on port 8081
2020-12-08 00:10:59 default[...]  "GET /_ah/start HTTP/1.1" 302
...

If I try a specific endpoint, I get these outputs (for one call):

2020-12-08 01:05:57 default[...]  "GET /my_api/some_endpoint HTTP/1.1" 500
2020-12-08 01:05:58 default[...]  "GET /favicon.ico HTTP/1.1" 500 <-- not sure what this is about

Also, I noticed that unlike in my local run, the gcloud app never outputs "Connected to DB!" which happens upon importing my database module into the routes.js file. Besides the app.yaml though, there's nothing different from running the app locally and on app engine, I'm just not sure why the app keeps restarting over and over every few seconds.

EDIT: So I noticed that, by default, app engine queries /_ah/start and /favicon.ico upon starting up the api, but since I don't have those endpoints coded, it errors and restarts. Is there any way to remove those two, or are they necessary for app engine to determine the app is working? OR at least I could add a /favicon.ico and /_ah/start endpoints, but what is the response format supposed to look like for it to respond? (I tried just returning 200 for both, but still get the same behavior)



from Server error 500 when deploying NodeJS Express app on GCP App Engine

No comments:

Post a Comment