Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use Express and GRPC in same service on Google Cloud Run without hitting Port Conflict

I have a NodeJS micro-service hosted on Google Cloud Run.

The service houses both an express server for user facing routes and a gRPC server for communicating with other internal micro-services.

Below is my code so far:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

....
//For the express server I am using an hard coded port because of port conflict with grpc server port
const app = express();
const hardCodedPort=3000; //I can't use process.env.PORT here because grpc server below needs it
app.listen(hardCodedPort);
......

//For grpc I am NOT using an hardcoded port, I am listening to the port provided by Cloud Run as shown below
gRPCServer.bindAsync(`0.0.0.0:${process.env.PORT}`, grpc.ServerCredentials.createInsecure(), () => {
      gRPCServer.start();
});

Now, owing to the fact that Cloud Run can spin very many instances of the above service will I hit a port conflict for my express server since it is always listening on an hard coded port?

>Solution :

The Cloud Run Frontend (GFE) only supports two ports: 80 and 443. If a client connects to port 80, the client will be redirected to port 443. In other words, your Cloud Run service can only support one internal port number, which defaults to 8080 (configurable). Your application can only listen for connections on one port.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading