Reputation: 8140
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!
Upvotes: 3
Views: 5234
Reputation: 865
I'm testing an application using Red Hat Developer Sandbox. I had the same error message page when trying to access the endpoint indicated by Openshift console.
The issue on my side was that the Ingress rule was missing.
I fixed it switching to the admin view, then neworking, and ingress. There I just changed service name, port and path to match my service, and host to match what openshift has created for me. That worked
Upvotes: 1
Reputation: 134
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"
Upvotes: 1