Search code examples
node.jsopenshift

Openshift node.js successful deployment, but "Application is not available"


I'm having a problem getting a node.js app to run on Openshift.

I've set up my openshift project to pull from a git repo.

My server.listen call is being made like this:

var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 8080;
var ip = process.env.OPENSHIFT_NODEJS_IP || process.env.IP || '127.0.0.1';

var server = http.createServer(myServerFunction);
server.listen(port, ip);

The pull and build work fine. I can see in the pod terminal that my app is running because there is some console.log output indicating this. I can also see that neither process.env.OPENSHIFT_NODEJS_IP nor process.env.IP exist, and so the port has defaulted to 8080.

If I go into the pod's terminal and execute curl http://localhost:8080 I see precisely the html output I would expect from my app.

However, when I click on the overview tab and find the external url for my app (which is of the format http://<application>-<domain>.1d35.starter-us-east-1.openshiftapps.com), clicking that link results in openshift's "Application is not available" error page.

It seems to me that my node app is running perfectly well, but is not connected to the external url. I suspect that 8080 is not the correct port, and that I am required to do more configuration in order for my nodejs app to receive a value at process.env.OPENSHIFT_NODEJS_PORT.

In other stackoverflow answers I've also seen 0.0.0.0 as the default when process.env.OPENSHIFT_NODEJS_IP is not set. Could this make a difference?

Overall, how can I make the external url link to my nodejs server?

Thanks for any help!


Solution

  • go to
    Applications > Services,
    click on your service,
    click Actions > Edit YAML,
    In ports sections,
    change port and targetPort to the port that your nodejs application is running on,
    in my case it was on port 8000,
    so i gave like this

    port: 8000
    protocol: TCP
    targetPort: 8000
    

    Also, check that app is running on "0.0.0.0", not "127.0.0.1"