Openshift 503 в приложението node.js с hapi

Имам приложение node.js, използващо hapi, което се опитвам да хоствам на 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.

Всяка помощ ще бъде високо оценена. Благодаря на всички!


person Scott Boyd    schedule 31.03.2016    source източник


Отговори (1)


Можете ли да опитате да използвате хост вместо адрес като този:

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

Също така мисля, че open shift също излага променлива на средата за порта.

person Angel Ramirez    schedule 01.04.2016