试图将我的第一个node.js应用程序部署到Heroku时,Web dynos不断崩溃 [英] Web dynos keep crashing while trying to deploy my first node.js app to Heroku

查看:113
本文介绍了试图将我的第一个node.js应用程序部署到Heroku时,Web dynos不断崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ foreman start 

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

  web:node server.js 
code>

这是我的package.json

 <$ c 
name:node-example,
version:0.0.1,
dependencies:{
express: 3.1.0,
jade:*,
socket.io:*,
下划线:*
}
}

所以我开始用
$开始dynos b $ b

  $ heroku ps:缩放web = 1 
缩放网络动态...完成,现在正在运行1


$ heroku ps
=== web(1X):`node server.js`
web.1:重启2013/09/27 22:10:44(〜34s前)

稍后

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

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



编辑:这是一些日志

  2013-09-27T12 :10:47.177359 + 00:00 heroku [web.1]:使用命令`node server.js`启动进程
2013-09-27T12:10:48.381526 + 00:00 app [web.1]:Server启动并运行。转到http://127.0.0.1:8080
2013-09-27T12:10:48.342939 + 00:00 app [web.1]:info:socket.io开始
2013-09-27T12 :11:48.499022 + 00:00 heroku [web.1]:错误R10(引导超时) - > Web进程无法在启动60秒内绑定到$ PORT
2013-09-27T12:11:48.499325 + 00:00 heroku [web.1]:使用SIGKILL停止进程
2013-09-27T12 :11:49.656186 + 00:00 heroku [web.1]:状态从开始更改为崩溃
2013-09-27T12:11:49.643225 + 00:00 heroku [web.1]:进程已退出,状态为137

EDI:server.js

  var portx = process.env.PORT; //这是我的加法

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); //到这里

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});
});
$ b 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(){
参与者= _.without(participants,_。findWhere(participants,{id:socket.id}));
io.sockets.emit(userDisconnected,{id:socket.id,sender:system} );
});

});
$ b $ 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]:服务器启动并运行。转到http://127.0.0.1:31707
2013-09-28T02:39:50.974347 + 00:00 heroku [web.1]:错误R10(启动超时) - > Web进程无法在启动60秒内绑定到$ PORT
2013-09-28T02:39:50.974557 + 00:00 heroku [web.1]:使用SIGKILL停止进程
2013-09-28T02 :39:52.927176 + 00:00 heroku [web.1]:进程已退出,状态为137
2013-09-28T02:39:52.945829 + 00:00 heroku [web.1]:状态从开始更改为崩溃


解决方案

我无法确定没有Node代码您创建服务器,但是从日志中看起来您没有在正确的端口上侦听。

Heroku为应用程序分配一个应用程序必须监听的端口(它被设置为PORT环境变量)。如果你在60年代没有连接到这个端口,它会杀死你的应用程序,这似乎是发生了什么。



更新:
事实上,根据你的web.1日志条目,它看起来像你试图监听端口8080.我认为这是极不可能的,这是Heroku提供的端口。您可以从process.env.PORT获取Heroku提供的端口,然后在其上进行监听。


$ foreman start

creates a link with my working app I have a file Called Procfile that contains:

web: node server.js

Here is my package.json

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

So I go to start the "dynos" with

 $ 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)

a little later

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

Any ideas on where I go from here?

EDIT: Here are some logs

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

Now I get this similar error.

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

解决方案

I can't be sure without the Node code where you create the server, however from the logs it looks like you are not listening on the correct port.

Heroku assigns your application a port (which is set as the "PORT" environment variable) that your application must listen on. If you do not connect to this port within 60s, it will kill your app, and this seems to be what is happening.

UPDATE: In fact, based on your web.1 log entry, it looks like you are trying to listen on port 8080. I think it is highly unlikely that this is the port provided by Heroku. You can get the port Heroku provides from process.env.PORT, and then listen on that.

这篇关于试图将我的第一个node.js应用程序部署到Heroku时,Web dynos不断崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆