在带有hapi的node.js应用上的Openshift 503

时间:2016-03-31 23:31:57

标签: javascript node.js openshift hapijs

我有一个使用hapi的node.js应用程序,我正试图在OpenShift上托管。我已将应用程序上传到服务器,它显然正在读取package.json文件并运行app.js文件。

但是,当我访问该网站时,收到503错误。

Package.json文件:

{
"name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "dependencies": {
    "after": "^0.8.1",
    "bcryptjs": "2.3.0",
    "bootstrap": "^3.3.6",
    "forever": "^0.15.1",
    "gulp": "^3.9.0",
    "gulp-nodemon": "^2.0.4",
    "handlebars": "4.0.5",
    "hapi": "^8.8.1",
    "hapi-auth-cookie": "^3.1.0",
    "knex": "^0.9.0",
    "mysql": "^2.9.0",
    "nodemon": "^1.8.0",
    "request": "^2.69.0",
    "tree-model": "^1.0.4"
  },
  "devDependencies": {},
  "scripts": {
    "start": "node server.js"
  }
  "author": "",
  "license": "ISC"
}

*注意:存储库信息已从package.json粘贴中删除。

app.js文件:

var Hapi = require('hapi');
var fs = require('fs');

fs.readFile('./bin/dbcfg.txt', 'utf8', function(err, data){
    if (err){
        console.log(err);
    }
    else{
        data = JSON.parse(data);
        process.env.client = data.client;
        process.env.host = data.connection.host;
        process.env.user = data.connection.user;
        process.env.password = data.connection.password;
        process.env.database = data.connection.database;
        fs.readFile('./bin/strategycfg.txt', 'utf8', function(err, data){
        if(err){
            console.log(err);
        }
        else{
            var strategyCFG = JSON.parse(data);
            server = new Hapi.Server();
            server.connection({ port : 3000, address: process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1' });
            server.register(require('hapi-auth-cookie'), function(err){
                if(err){
                    console.log(err);
                }
                server.auth.strategy('default', 'cookie',strategyCFG);
                server.auth.default('default');
                const defaultContext = {
                    title: 'App'
                };
                server.views({
                    engines: {
                        html: require('handlebars')
                    },
                    context: defaultContext,
                    path: ['public/html', 'private/html'],
                    layoutPath: 'public/templates',
                    layout: 'default'
                    //,
                    //helpersPath: 'views/helpers',
                    //partialsPath: 'views/partials'
                });
            });

            server.route(require('./lib/Routes'));

            server.start(function() {
                console.log('Running on 3000');
            });
        }
    });
}

});

我运行了rhc tail -a appname并收到了:

==> app-root/logs/haproxy.log <==
[WARNING] 090/180806 (276379) : config : log format ignored for proxy 'stats' since it has no log address.
[WARNING] 090/180806 (276379) : config : log format ignored for proxy 'express' since it has no log address.
[WARNING] 090/180806 (276379) : Server express/local-gear is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 090/180806 (276379) : proxy 'express' has no server available!
[WARNING] 090/180919 (276379) : Server express/local-gear is DOWN for maintenance.
[WARNING] 090/180919 (279772) : config : log format ignored for proxy 'stats' since it has no log address.
[WARNING] 090/180919 (279772) : config : log format ignored for proxy 'express' since it has no log address.
[WARNING] 090/180919 (279772) : Server express/local-gear is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 090/180919 (279772) : proxy 'express' has no server available!
[WARNING] 090/180923 (279772) : Server express/local-gear is DOWN for maintenance.

==> app-root/logs/haproxy_ctld.log <==
I, [2016-03-30T22:04:51.536078 #521102]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:11:34.136340 #49489]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:25:04.802167 #98826]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:29:56.842182 #117627]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:32:36.247075 #130978]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T22:39:12.046805 #156995]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T23:01:39.741187 #237078]  INFO -- : Starting haproxy_ctld
I, [2016-03-30T23:07:00.948129 #255019]  INFO -- : Starting haproxy_ctld
I, [2016-03-31T18:08:07.635718 #276393]  INFO -- : Starting haproxy_ctld
I, [2016-03-31T18:09:20.552771 #279795]  INFO -- : Starting haproxy_ctld

==> app-root/logs/npm-debug.log <==
5 error package.json npm can't find a package.json file in your current directory.
6 error System Linux 2.6.32-573.12.1.el6.x86_64
7 error command "node" "/opt/rh/nodejs010/root/usr/bin/npm" "install"
8 error cwd /var/lib/openshift/xxxxxxxx/app-root/logs
9 error node -v v0.10.35
10 error npm -v 1.4.28
11 error path /var/lib/openshift/xxxxxxxx/app-root/logs/package.json
12 error code ENOPACKAGEJSON
13 error errno 34
14 verbose exit [ 34, true ]

==> app-root/logs/nodejs.log <==
DEBUG: Sending SIGTERM to child...
DEBUG: Running node-supervisor with
DEBUG:   program 'server.js'
DEBUG:   --watch '/var/lib/openshift/xxxxxxx/app-root/data/.nodewatch'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'node|js|coffee'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/xxxxxxx/app-root/data/.nodewatch' for changes.
Running on 3000

“在3000上运行”让我觉得应用正在运行,但OpenShift网站给了我一个503。

非常感谢任何和所有帮助。谢谢大家!

1 个答案:

答案 0 :(得分:0)

您可以尝试使用主机而不是这样的地址:

server.connection({ host:'0.0.0.0', port: 3000});

此外,我认为open shift还会为端口公开环境变量。