【发布时间】:2014-05-10 04:45:38
【问题描述】:
我正在尝试创建一个简单的聊天应用程序,但 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>
谁能帮帮我?
【问题讨论】:
-
请检查是否有帮助:stackoverflow.com/questions/15693192/… 我看到您正在指定端口,但在这个问题中据说 Heroku 会自动分配端口。