我尝试了很多,但无法在 openshift 节点盒与 mongo 盒对话的简单平均应用程序中让节点连接到 Mongo。一切正常,但如果您转到 URL ,应用程序会出错(服务暂时不可用错误) 。
我使用了正确的环境变量,如果我 ssh 到实例并在本地连接到 mongo 或在应用程序根目录运行节点服务器,一切正常。
但是,如果我 git push 它,构建、部署等工作正常,但是当我转到应用程序 URL 时,它会出错。请帮忙。不确定问题出在哪里,因为代码在本地和 repo 目录中的 openshift 服务器上运行良好,在命令行中使用“节点服务器”。
==============================
**server.js**
=========
#!/bin/env node
// OpenShift sample Node application
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
// Load the module dependencies
var mongoose = require('./config/mongoose'),
express = require('./config/express'),
passport = require('./config/passport');
// Create a new Mongoose connection instance
var db = mongoose();
// Create a new Express application instance
var app = express();
// Configure the Passport middleware
var passport = passport();
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
app.listen(port, ipaddress, function() {
console.log('%s: Node server started on %s:%d ...',
Date(Date.now() ), ipaddress, port);
});
// Use the module.exports property to expose our Express application instance for external usage
module.exports = app;
===========================
development.js
==============
// Invoke 'strict' JavaScript mode
'use strict';
var dbDefault = process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_APP_NAME || 'mongodb://localhost:27017/someapp';
// Set the 'development' environment configuration object
module.exports = {
db : dbDefault ,
sessionSecret: 'developmentSessionSecret'
};
================================
mongoose.js
===========
// Invoke 'strict' JavaScript mode
'use strict';
// Load the module dependencies
var config = require('./config'),
mongoose = require('mongoose');
// Define the Mongoose configuration method
module.exports = function() {
// Use Mongoose to connect to MongoDB
var db = mongoose.connect(config.db);
// Load the application models
require('../app/core/models/user.server.model');
// Return the Mongoose connection instance
return db;
};
===========================
logs - node
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'