将 hapijs api 部署到 heroku

Deploying hapijs api to heroku

我有一个与 mongo(mongolabs,具体来说)一起工作的 hapijs 服务器,它在本地工作得很好,但在部署时它给我一个应用程序错误。这是我的日志片段:

2015-12-06T17:30:17.782595+00:00 heroku[web.1]: State changed from starting to crashed
2015-12-06T17:30:17.911448+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=angular-scaffold-backend.herokuapp.com request_id=616df52f-a5fb-482f-9f8b-cb2daab07142 fwd="161.0.214.224" dyno= connect= service= status=503 bytes=
2015-12-06T17:30:19.839856+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=angular-scaffold-backend.herokuapp.com request_id=0b623277-20d6-4e74-ab21-dbd31850332b fwd="161.0.214.224" dyno= connect= service= status=503 bytes=

我尝试了所有可能的答案来解决同样的问题,从更改端口以便 heroku 可以自动绑定它到更改 mongodb 以与 mongolabs 一起工作,删除了来自服务器创建的 IP 和许多其他我现在不记得的东西。这是我的服务器:

var hapi = require('hapi');
var inert = require('inert');
var mongoose = require('mongoose');
var routes = require('./routes');
var auth = require('hapi-auth-cookie');

var server = new hapi.Server();
server.connection({
    port: ~~process.env.PORT | 8000,
    routes: { cors: {
                    credentials: true,
                    origin: ["*"]
                } }
});
//changed these so theres no real data on the user/password part, but I got the real thing in my server
mongoose.connect('mongodb://<dbuser>:<password>@ds049104.mongolab.com:49104/angular-scaffold'); 

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function callback() {
    console.log("Connection with database succeeded.");
});

server.register([inert, auth], function(err){

  server.auth.strategy('session', 'cookie', {
    password: 'secretpasswordforencryption',
    cookie: 'angular-scaffold-cookie',
    ttl: 24 * 60 * 60 * 1000, // Set session to 1 day
    isSecure: false
  });

    server.route(routes.endpoints);

    server.start(function () {
        console.log('Server running at:', server.info.uri);
    });
});

提前致谢:)

问题是我在 package.json 上的启动脚本中的路径有错误 我拥有的是

"scripts": {
    "start": "node server/server.js"
  },

虽然我的应用程序中没有名为 server 的目录,所以我只更改为

"scripts": {
    "start": "node server"
  },

并且应用已正确部署。 (在为同一个应用程序部署前端时出现相同的错误,只是使用安装后脚本时出现错误)