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