【问题标题】:Deploying hapijs api to heroku将 hapijs api 部署到 heroku
【发布时间】:2016-03-11 06:47:51
【问题描述】:

我有一个使用 mongo(具体来说是 mongolabs)的 hapijs 服务器,它在本地工作得非常好,但是在部署时它给了我一个应用程序错误。这是我的日志的 sn-p:

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);
    });
});

提前谢谢:)

【问题讨论】:

  • 你有没有从 hapi 得到任何日志?
  • 不,没什么。我在这里看到的唯一另一件事是一个日志条目,上面写着“未找到”(不要认为这是来自 Hapi)

标签: mongodb heroku deployment hapijs


【解决方案1】:

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-15
    • 2014-10-21
    • 2011-12-18
    • 2014-08-02
    • 2020-07-28
    • 2012-08-10
    • 2012-04-29
    • 1970-01-01
    相关资源
    最近更新 更多