在openshift中使用Mongodb盒式节点盒连接错误

时间:2015-05-21 20:14:24

标签: node.js mongodb connection openshift openshift-cartridge

我尝试了很多但是无法通过与mongo盒式磁带通信的openshift节点盒中的简单平均应用程序获得节点连接到Mongo。一切顺利,但应用程序错误输出(服务暂时不可用错误)如果您转到URL

我使用了适当的环境变量,如果我ssh到实例并在本地连接到mongo或在app root运行节点服务器,一切正常。

但是如果我git推送它,构建,部署等工作正常但是当我转到应用程序URL时它会出错。 请帮忙。不知道问题是什么,因为代码在本地和在repo目录中的openshift服务器上使用命令行中的'node server'工作正常。

==============================
    **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'

0 个答案:

没有答案