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:
....
//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?
CodePudding user response:
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.