Deployed Node app to OpenShift successfully, OpenS

2019-07-27 18:07发布

问题:

So here are the steps I've taken so far:

  1. Created application on openshift
  2. Cloned application's repo
  3. Deleted all files for the sample app in the cloned repo
  4. Added my project files
  5. Performed a Git-Push which completed successfully.

I still see the default landing page:

The only odd thing I see in the deployment logs this warning, which makes no senses because it's not my code doing that (I'm basically just trying to deploy the sample app from Express)

Any ideas as to what could be causing this? I'm trying to dump Heroku but can't get basic things to work.

UPDATE: I found this KB article which explains how to run your own file (why this information isn't better documented and part of the basic tutorial is beyond me). It is still unclear to me whether the code in server.js is needed or not... Or I'm expected to always use server.js as a shell to all my code.

https://www.openshift.com/kb/kb-e1048-how-can-i-run-my-own-nodejs-script

回答1:

I found the answer here:

https://www.openshift.com/blogs/run-your-nodejs-projects-on-openshift-in-two-simple-steps

The gist of it is this:

  • Change main in package.json to set main to yourApp.js (as per this article)
  • Make sure you're starting your server with the right IP and Port on OpenShift (see below)

app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080); app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');

and then

http.createServer(app).listen(app.get('port'), app.get('ip'), function(){ console.log('Express server listening on port ' + app.get('port')); });