3
$ foreman start

创建与我的工作应用程序的链接我有一个名为 Procfile 的文件,其中包含:

web: node server.js

这是我的 package.json

{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.1.0",
    "jade": "*",
    "socket.io": "*",
    "underscore": "*"
  }
}

所以我去开始“dynos”

 $ heroku ps:scale web=1
Scaling web dynos... done, now running 1


$ heroku ps
=== web (1X): `node server.js`
web.1: restarting 2013/09/27 22:10:44 (~ 34s ago)

一会儿

$ heroku ps
=== web (1X): `node server.js`
web.1: crashed 2013/09/27 22:11:49 (~ 10s ago)

关于我从这里去哪里的任何想法?

编辑:这里有一些日志

2013-09-27T12:10:47.177359+00:00 heroku[web.1]: Starting process with command `node server.js`
2013-09-27T12:10:48.381526+00:00 app[web.1]: Server up and running. Go to http://127.0.0.1:8080
2013-09-27T12:10:48.342939+00:00 app[web.1]: info: socket.io started
2013-09-27T12:11:48.499022+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2013-09-27T12:11:48.499325+00:00 heroku[web.1]: Stopping process with SIGKILL
2013-09-27T12:11:49.656186+00:00 heroku[web.1]: State changed from starting to crashed
2013-09-27T12:11:49.643225+00:00 heroku[web.1]: Process exited with status 137

EDI:server.js

var portx = process.env.PORT;  // This is my addition

var express = require("express")
  , app = express()
  , http = require("http").createServer(app)
  , io = require("socket.io").listen(http)
  , _ = require("underscore");

var participants = []

app.set("ipaddr", "127.0.0.1");

app.set("port", portx);  // to here

app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.use(express.static("public", __dirname + "/public"));
app.use(express.bodyParser());
app.get("/", function(request, response) {

  response.render("index");

});

app.post("/message", function(request, response) {

  var message = request.body.message;

  if(_.isUndefined(message) || _.isEmpty(message.trim())) {
    return response.json(400, {error: "Message is invalid"});
  }

  var name = request.body.name;
  io.sockets.emit("incomingMessage", {message: message, name: name});
  response.json(200, {message: "Message received"});
});

io.on("connection", function(socket){

  socket.on("newUser", function(data) {
    participants.push({id: data.id, name: data.name});
    io.sockets.emit("newConnection", {participants: participants});
  });

  socket.on("nameChange", function(data) {
    _.findWhere(participants, {id: socket.id}).name = data.name;
    io.sockets.emit("nameChanged", {id: data.id, name: data.name});
  });

  socket.on("disconnect", function() {
    participants = _.without(participants,_.findWhere(participants, {id: socket.id}));
    io.sockets.emit("userDisconnected", {id: socket.id, sender:"system"});
  });

});

http.listen(app.get("port"), app.get("ipaddr"), function() {
  console.log("Server up and running. Go to http://" + app.get("ipaddr") + ":" + app.get("port"));
});

现在我得到这个类似的错误。

2013-09-28T02:38:51.301568+00:00 app[web.1]: info: socket.io started
2013-09-28T02:38:51.363825+00:00 app[web.1]: Server up and running. Go to http://127.0.0.1:31707
2013-09-28T02:39:50.974347+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2013-09-28T02:39:50.974557+00:00 heroku[web.1]: Stopping process with SIGKILL
2013-09-28T02:39:52.927176+00:00 heroku[web.1]: Process exited with status 137
2013-09-28T02:39:52.945829+00:00 heroku[web.1]: State changed from starting to crashed
4

2 回答 2

8

如果没有创建服务器的节点代码,我无法确定,但是从日志看来,您没有在正确的端口上监听。

Heroku 为您的应用程序分配一个端口(设置为“PORT”环境变量),您的应用程序必须监听该端口。如果你在 60 秒内没有连接到这个端口,它会杀死你的应用程序,这似乎就是正在发生的事情。

更新:事实上,根据您的 web.1 日志条目,您似乎正在尝试侦听端口 8080。我认为这不太可能是 Heroku 提供的端口。你可以从 process.env.PORT 获取 Heroku 提供的端口,然后监听它。

于 2013-09-27T17:36:04.560 回答
0

尝试查看您的仪表板,检查您是否拥有至少一个 Dynos。我添加了多个应用程序并使用免费路径,因此它会在应用程序之间不断移动 Dyno。

祝你好运。

于 2013-11-20T06:22:17.443 回答