Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Foreman start可以工作,但heroku.app不能';T_Node.js_Heroku - Fatal编程技术网

Node.js Foreman start可以工作,但heroku.app不能';T

Node.js Foreman start可以工作,但heroku.app不能';T,node.js,heroku,Node.js,Heroku,我试图创建一个简单的聊天应用程序,但heroku给了我错误: 2014-05-09T20:19:43.315159+00:00 heroku[api]: Enable Logplex by zwhitchcox@gmail.com 2014-05-09T20:19:43.315241+00:00 heroku[api]: Release v2 created by zwhitchcox@gmail.com 2014-05-09T20:20:06+00:00 heroku[slug-compile

我试图创建一个简单的聊天应用程序,但heroku给了我错误:

2014-05-09T20:19:43.315159+00:00 heroku[api]: Enable Logplex by zwhitchcox@gmail.com
2014-05-09T20:19:43.315241+00:00 heroku[api]: Release v2 created by zwhitchcox@gmail.com
2014-05-09T20:20:06+00:00 heroku[slug-compiler]: Slug compilation started
2014-05-09T20:20:25.635919+00:00 heroku[api]: Release v3 created by zwhitchcox@gmail.com
2014-05-09T20:20:25.532933+00:00 heroku[api]: Scale to web=1 by zwhitchcox@gmail.com
2014-05-09T20:20:25.635919+00:00 heroku[api]: Deploy 62543a1 by zwhitchcox@gmail.com
2014-05-09T20:20:25+00:00 heroku[slug-compiler]: Slug compilation finished
2014-05-09T20:20:26.536745+00:00 heroku[api]: Scale to web=1 by zwhitchcox@gmail.com
2014-05-09T20:20:27.704168+00:00 heroku[web.1]: Starting process with command `node server.js`
2014-05-09T20:20:29.653123+00:00 app[web.1]: info: socket.io started
2014-05-09T20:21:29.273275+00:00 heroku[web.1]: State changed from starting to crashed
2014-05-09T20:21:29.274054+00:00 heroku[web.1]: State changed from crashed to starting
2014-05-09T20:21:27.960123+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-05-09T20:21:27.960449+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-05-09T20:21:29.258964+00:00 heroku[web.1]: Process exited with status 137
2014-05-09T20:21:32.343694+00:00 app[web.1]: info: socket.io started
2014-05-09T20:21:31.092312+00:00 heroku[web.1]: Starting process with command `node server.js`
2014-05-09T20:21:44.023410+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=boiling-wave-8331.herokuapp.com request_id=19d30ac7-a101-4ace-b993-89d02092be0f fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
2014-05-09T20:22:34.214614+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=boiling-wave-8331.herokuapp.com request_id=09ffb0f3-2c08-4d12-8b9c-37fa4c112680 fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
2014-05-09T20:22:32.984322+00:00 heroku[web.1]: State changed from starting to crashed
2014-05-09T20:22:32.972699+00:00 heroku[web.1]: Process exited with status 137
2014-05-09T20:22:31.694958+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-05-09T20:22:31.695682+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-05-09T20:26:46.594041+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=boiling-wave-8331.herokuapp.com request_id=7823d4c1-f102-4e64-b47f-c50e5c9452c4 fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
2014-05-09T20:26:46.280531+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=boiling-wave-8331.herokuapp.com request_id=1b4b66ba-f5f5-4fca-affc-06b3b6f3dc38 fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
2014-05-09T20:27:21.798690+00:00 heroku[api]: Scale to web=1 by zwhitchcox@gmail.com
2014-05-09T20:27:32.718961+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=boiling-wave-8331.herokuapp.com request_id=ca1e9a7a-b7c8-4c67-a064-e069e0940dd6 fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
2014-05-09T20:27:33.050677+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=boiling-wave-8331.herokuapp.com request_id=50a8f3e7-a60a-4f76-8eb4-7b17c9e26155 fwd="50.193.187.85" dyno= connect= service= status=503 bytes=
然而,每当我使用foreman start时,我的应用程序都会工作

这是我的服务器代码:

var     express         = require('express'),
        app                 = express(),
            server          = require('http').createServer(app),
        io          = require('socket.io').listen(server),
        port            = 8090,
        chatClients             = new Object();

server.listen(port);

app.get('/', function (req, res) {
    res.sendfile(__dirname+'/index.html');
});

io.sockets.on("connection", function(socket) {
    socket.on('message', function(data) {
        io.sockets.emit('receiveMessage',{yourMessage:data.message});
    });
});
这是我的index.html代码:

<div id="messages"></div>
<input id="message">
<button id="submit">send</button>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script>
socket = null;
socket = io.connect();

socket.on('receiveMessage', function(data) {
    var message = document.createElement('p');
    message.innerHTML = data.yourMessage;
    document.getElementById('messages').appendChild(message);
});

document.getElementById('submit').onclick = function() {
    socket.emit('message',{message:document.getElementById('message').value});
}
</script>

邮寄
socket=null;
socket=io.connect();
socket.on('receiveMessage',函数(数据){
var message=document.createElement('p');
message.innerHTML=data.yourMessage;
document.getElementById('messages').appendChild(message);
});
document.getElementById('submit')。onclick=function(){
emit('message',{message:document.getElementById('message').value});
}

有人能帮我一下吗?

Heroku随机分配端口,您需要确保将您的环境分离出来

var express     = require('express'),
    app         = express(),
    server      = require('http').createServer(app),
    io          = require('socket.io').listen(server),
    port        = (process.env.NODE_ENV == 'production') ? process.env.PORT : 8090,
    chatClients = new Object();

server.listen(port);

app.get('/', function (req, res) {
    res.sendfile(__dirname+'/index.html');
});

io.sockets.on("connection", function(socket) {
    socket.on('message', function(data) {
        io.sockets.emit('receiveMessage',{yourMessage:data.message});
    });
});
然后执行:
heroku config:set NODE\u ENV=production


请在此处阅读更多信息:

请检查这是否有帮助:我看到您正在指定端口,但在这个问题中,据说Heroku会自动分配端口。