-1

Edit 2 - Final Notes

Solution below worked for me, however you still need to manually specify the mongo connection credentials as shown above for the application to run correctly, otherwise you will get a mongo auth error.

Edit 1 - Added full keystone.js

keystone.js

// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').load();

// Require keystone
var keystone = require('keystone');

var mongoDbConnectionString =  process.env.OPENSHIFT_MONGODB_DB_URL || 'mongodb://localhost/********';

var host = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

var port = process.env.OPENSHIFT_NODEJS_PORT  || process.env.OPENSHIFT_INTERNAL_PORT || 3000;

// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.

keystone.init({

    'name': '********',
    'brand': '********',

    'less': 'public',
    'static': 'public',
    'favicon': 'public/favicon.ico',
    'views': 'templates/views',
    'view engine': 'jade',

    'emails': 'templates/emails',
    'mongo': mongoDbConnectionString,
    'host': host,
    'port':  port,
    'auto update': true,
    'session': true,
    'auth': true,
    'user model': 'User',
    'cookie secret': '********'


});

// Load your project's Models

keystone.import('models');

// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js

keystone.set('locals', {
    _: require('underscore'),
    env: keystone.get('env'),
    utils: keystone.utils,
    editable: keystone.content.editable
});

// Load your project's Routes

keystone.set('routes', require('./routes'));

// Setup common locals for your emails. The following are required by Keystone's
// default email templates, you may remove them if you're using your own.

keystone.set('email locals', {
    logo_src: '/images/logo-email.gif',
    logo_width: 194,
    logo_height: 76,
    theme: {
        email_bg: '#f9f9f9',
        link_color: '#2697de',
        buttons: {
            color: '#fff',
            background_color: '#2697de',
            border_color: '#1a7cb7'
        }
    }
});

// Setup replacement rules for emails, to automate the handling of differences
// between development a production.

// Be sure to update this rule to include your site's actual domain, and add
// other rules your email templates require.

keystone.set('email rules', [{
    find: '/images/',
    replace: (keystone.get('env') == 'production') ? 'http://www.your-server.com/images/' : 'http://localhost:3000/images/'
}, {
    find: '/keystone/',
    replace: (keystone.get('env') == 'production') ? 'http://www.your-server.com/keystone/' : 'http://localhost:3000/keystone/'
}]);

// Load your project's email test routes

keystone.set('email tests', require('./routes/emails'));

// Configure the navigation bar in Keystone's Admin UI

keystone.set('nav', {
    'posts': ['posts', 'post-categories'],
    'creations': 'galleries',
    'contact us': 'enquiries',
    'users': 'users'
});

// Start Keystone to connect to your database and initialise the web server

    console.log('%s: IP Set.', host);
    console.log('%s: Port Set.', port);

keystone.start();

I am trying to build my first Keystone.js, got it running fine locally on my machine.

Now, i am trying to push my site to Openshift and failing miserably.

I have gotten mongo to connect by adding this to keystone.js:

var mongoDbConnectionString =  process.env.OPENSHIFT_MONGODB_DB_URL || 'mongodb://localhost/*********';

However i cannot get the thing to run correctly as it seems to be having issues binding to the ip and port i am feeding it on Openshift, i am using the following code:

var host = process.env.OPENSHIFT_NODEJS_IP || process.env.OPENSHIFT_INTERNAL_IP || "127.0.0.1";

var port = process.env.OPENSHIFT_NODEJS_PORT  || process.env.OPENSHIFT_INTERNAL_PORT || 3000;

Combined with:

keystone.init({

'name': '*********',
'brand': '*********',

'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'jade',

'emails': 'templates/emails',
'mongo': mongoDbConnectionString,
'host': host,
'port':  port,
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
'cookie secret': '*********'


});

But i keep getting:

==> app-root/logs/nodejs.log <==
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
....

with 'node keystone.js'
DEBUG: Sending SIGTERM to child...

Now i have checked the env on the Openshift instance and they seem to be correct variable, i am getting port 8080 and what seems like a correct IP address.

I've also tried hard coding the port and address parts but it seems to make no difference, and also not really workable for local testing.

I'm obviously missing something simple here, so help greatly appreciated!

Thanks

Gareth Jeanne
  • 1,410
  • 2
  • 19
  • 35

1 Answers1

0

Edit 1 - Ignoring server.js code as per @GarethJeanne's comment

If your entry point is keystone.js and your not using server.js at all (which renders my previous answer mute), then you need to make sure you're using Keystone 0.3.3 or newer.

This issue was addressed in Pull Request 1127, which was merged on Feb. 28, and first included in version 0.3.3, which was released on Mar. 8.

I don't believe this is a Keystone issue. You're obviously not using Keystone's out-of-the-box initialization and startup, so Keystone is handling the creation or initialization of your Express app.

Since you're not sharing all of your code (e.g. self.initializeServer()), I will assume you're correctly setting up Express and connecting it to your Keystone app instance.

I will likewise assume self.app is an instance of Express.

From the code you submitted, the only problem I see is that you're passing 'self.port' and 'self.ipaddress' to self.app.listen() with single quotes around each argument.

This would definitely cause a listen EACCES error.

Try removing the single quotes surrounding 'self.port' and 'self.ipaddress' on the self.app.listen() call.

self.start = function() { // Start the app on the specific interface (and port). self.app.listen(self.port, self.ipaddress, function() { console.log('%s: Node server started on %s:%d ...', Date(Date.now() ), self.ipaddress, self.port); }); };

I can't guarantee the rest of your app will work, but it should, at the very least, eliminate the listen EACCES error.

JME
  • 3,592
  • 17
  • 24
  • Hi JME, thanks for your reply, the inclusion of the quotes above was a typo, i have updated the questions with full version of server.js and keystone.js for you to take a look at. – Gareth Jeanne Mar 08 '15 at 21:15
  • @GarethJeanne, I'm a bit confused. What is the entry point for your app (`keystone.js` or `server.js`)? From the error log in your question I'm going to assume `keystone.js`. If that's the case, can you tell me what version of Keystone you're using? – JME Mar 09 '15 at 01:06
  • sorry brain dead tired post, i am only using the keystone.js and that is the entry point. So please ignore the server.js, i have updated the question above. Version wise, i am using the keystone-utils@0.1.13 and generator-keystone@0.3.0 – Gareth Jeanne Mar 09 '15 at 18:24
  • @GarethJeanne, actually I was inquiring about your Keystone version, not the generator, but I will assume you're using `0.3.2` or older. I've updated my answer based on this new information. – JME Mar 09 '15 at 21:43
  • Yes, this has sorted it, though the process of updating to 0.3.3 was a little bit painful, easy enough for the remote instance on openshift as i just specified it in my package.json, but had issue getting all the modules available locally. – Gareth Jeanne Mar 10 '15 at 00:20
  • Sorry it took so long to figure out the issue. You're original question was a bit cryptic. I authored this PR several days ago when another Keystone consumer had the same issue. I'm glad it fixed your problem as well. – JME Mar 10 '15 at 00:24