问题描述:

I've been struggling days just to upload my nodejs app on a cloud and i tried openshift because it seems nice and i've commited my folder and files into my github, i've created a ssh key and everything, i've pushed my app to my openshift app page, and it displays the normal guide on how to push your app to openshift instead of my app.

I've got no idea on how to fix it, i've done everything i could. I'm not getting any errors. When i do git log, it just says the author and date, no errors. Please, if somebody knows how to fix this, please tell me!

Server.js File

var express = require('express');

var static = require('node-static');

var env = process.env.NODE_ENV || 'development';

var app = express();

var config = require('./server/config/config')[env];

require('./server/config/express')(app, config);

require('./server/config/mongoose')(config);

require('./server/config/passport')();

require('./server/config/routes')(app);

app.listen(config.port);

console.log("Server running on port: " + config.port);

网友答案:

Ok, it looks like you're not listening on the correct ip and port. Here is the code to get the correct ip/port on OpenShift:

// if on OpenShift, use OpenShift ip/port, else use your local ip/port
var ipAddress = process.env.OPENSHIFT_INTERNAL_IP || process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_INTERNAL_IP || process.env.OPENSHIFT_NODEJS_PORT || 3030;

   // The rest of the code
   :
   :


app.listen(port, ipAddress, function() {
  console.log('%s: Node server started on %s:%d ...',
                 new Date() ), ipAddress, port);
});
网友答案:

With OpenShift, you need to bind to a host-provided virtual port AND IP address.

Also, if your main entrypoint is not a script named server.js, then you'll need to configure your package.json in order to suit your needs.

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

相关阅读:
Top