Home > Software design >  Google Cloud App Engine - NestJS App deploys fine and runs instance, but can't access it
Google Cloud App Engine - NestJS App deploys fine and runs instance, but can't access it

Time:07-09

I am trying to host a NestJS application on Google App Engine. I'm using Cloud Build to deploy the app into App Engine after certain action on my GitHub repo.

Everything goes fine; the app builds and is deployed to App Engine. Even an instance is created for said deployment. However I cannot seem to access the host that's assigned to the service where I'm hosting the application on. I don't understand why as the test NodeJS project for App Engine ran just fine. This is what I get when trying to visit the endpoint.

app.yaml

runtime: nodejs16
instance_class: F4
service: rest

cloudbuild.yaml

steps:
- name: node:16.0.0
  entrypoint: npm
  args: ["install"]
- name: node:16.0.0
  entrypoint: npm
  args: ["run", "build"]
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy", "-v", "20220628t175507"]
timeout: "1600s"

I don't understand what I'm doing wrong. Just for reference the application is simply a REST API app, only utilized to make requests to.

CodePudding user response:

Solved

GAE docs do not tell you this (they slightly hint it when talking about app.yaml's environment_variables, but not explicitly).

Make sure the port your Nest application is pointing to is process.env.PORT as GAE sets the best port available for your application automatically. Since I had a static value assigned to the port it wouldn't run.

Basically changed:

app.run(3000);

To:

app.run(process.env.PORT);

Ran latest build and everything works perfectly fine.

  • Related