编辑 2 - 最后的笔记
下面的解决方案对我有用,但是您仍然需要手动指定如上所示的 mongo 连接凭据才能使应用程序正确运行,否则您将收到 mongo auth 错误。
编辑 1 - 添加了完整的 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();
我正在尝试构建我的第一个 Keystone.js,让它在我的机器上本地运行良好。
现在,我正试图将我的网站推送到 Openshift 并且惨遭失败。
我已经通过将它添加到 keystone.js 来连接 mongo:
var mongoDbConnectionString = process.env.OPENSHIFT_MONGODB_DB_URL || 'mongodb://localhost/*********';
但是我无法让事情正常运行,因为它似乎在绑定到我在 Openshift 上提供的 ip 和端口时遇到问题,我正在使用以下代码:
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;
结合:
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': '*********'
});
但我不断得到:
==> 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...
现在我检查了 Openshift 实例上的环境,它们似乎是正确的变量,我正在获取端口 8080,并且似乎是正确的 IP 地址。
我也尝试过对端口和地址部分进行硬编码,但似乎没有什么区别,而且对于本地测试也不是真正可行的。
我显然在这里遗漏了一些简单的东西,非常感谢您的帮助!
谢谢