Tôi khá mới đối với tất cả các công nghệ này (bao gồm phần JavaScript) để bạn có thể phải chịu đựng với tôi tại đây.Lỗi ứng dụng khi cố gắng triển khai ứng dụng Node.js/Express/Socket.io trên Heroku
Tôi đã làm theo hướng dẫn ChatApp trên tài liệu Socket.IO khá chặt chẽ và đã sửa đổi ứng dụng theo ý thích của tôi; tuy nhiên, tôi không nghĩ rằng tôi đã thay đổi nhiều về mặt tương tác và công cụ của máy chủ. Vấn đề của tôi là không có vấn đề gì tôi làm, tôi dường như không thể để có được ứng dụng của tôi để chạy thành công trên Heroku. Tôi nhận được thông báo lỗi này khi cố gắng tải ứng dụng:
Lỗi ứng dụng Đã xảy ra lỗi trong ứng dụng và trang của bạn không thể được phân phối. Vui lòng thử lại sau vài phút. Nếu bạn là chủ sở hữu ứng dụng, hãy kiểm tra nhật ký của bạn để biết chi tiết.
Tôi không chắc chắn nếu tôi thiếu điều gì đó rõ ràng hoặc gì.
Đây là chính tập tin index.js tôi:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
app.use("/css", express.static(__dirname + '/css'));
//array of users currently in chat
var people = {};
io.on('connection', function(socket){
console.log('user connected!');
socket.on('join', function(name){
people[socket.id] = name; //create entry in 'people' with new user
socket.emit("update", "You have connected to the server.");
io.sockets.emit("update", name + " has joined the server.");
io.sockets.emit("update_people_list", people);
});
socket.on('disconnect', function(){
console.log('user disconnected!');
if(people[socket.id] != ""){
io.sockets.emit("update", people[socket.id] + " has left the server.");
delete people[socket.id];
io.sockets.emit("update_people_list", people);
}
});
socket.on('chat message', function(msg){
console.log('message: ' + msg);
io.sockets.emit('chat message', people[socket.id], msg);
});
});
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });
index.html
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function(){
var ready = false;
var socket = io.connect();
$("#chat").hide();
$(".canvasDiv").hide();
$("#name").focus();
//prevent form from being submitted without name
$("form").submit(function(event){
event.preventDefault();
});
//allows entering by hitting 'Enter' for name
$("#name").keypress(function(e){
if(e.which == 13) { //if ENTER key
var name = $("#name").val();
if(name != ""){
socket.emit("join", name);
$("#login").detach();
$("#chat").show();
$("#msg").focus();
ready = true;
}
}
});
$('#chatform').submit(function(){ //when submit chat message
socket.emit('chat message', $('#msg').val()); //emit message + value of input
$('#msg').val(''); //empty field?
return false; //so that the page doesn't refresh
});
//SOCKET LISTENING
socket.on('chat message', function(user, msg){
if(ready){
$('#messages').append("<p><strong><span class='chat-user'>" + htmlEntities(user) + " </span></strong>: " + htmlEntities(msg) + "</p>");
//adjust height and scroll as need be:
var $container = $('#messages');
var height = $container.get(0).scrollHeight;
$container.scrollTop(height);
}
});
socket.on("update", function(io_message){
if(ready){
$('#messages').append("<p class='notification'>" + htmlEntities(io_message) + "</p>")
}
});
socket.on("update_people_list", function(people){
if(ready){
$("#people").empty(); //clear to refresh it
$.each(people, function(client_id, name){
$('#people').append("<p class='notification'>" + htmlEntities(name) + "</p>");
});
var $container = $("#messages");
var height = $container.get(0).scrollHeight;
$container.scrollTop(height);
}
});
});
</script>
Bên cạnh đó, tập tin package.json tôi
{
"name": "socket-chat-example",
"version": "0.0.1",
"description": "my first socket.io app",
"dependencies": {
"express": "^4.6.1",
"socket.io": "^1.0.6"
}
}
Procfile:
web: node index.js
.210
.gitignore:
node_modules/
này giải quyết vấn đề của tôi. Cảm ơn. –
'nhật ký của cô ấy đã giúp tôi tìm ra rằng sự thể hiện đã được cài đặt trong devDependencies và không phụ thuộc vào. Tôi cài đặt nó trong phụ thuộc và nó đã làm việc! Cảm ơn! – Siddharth