Heroku node.js部署。应用程序错误

时间:2017-01-02 13:57:01

标签: javascript html node.js heroku server

我尝试将我的node.js应用程序部署到Heroku。当我试图打开网站时,我收到了这个错误:

  

应用程序中发生错误,无法提供您的页面

这是我的index.html:

<html>

    <head>
        <title>Title</title>
        <script src = "http://code.jquery.com/jquery-latest.min.js"></script> 
        <script src = "/socket.io/socket.io.js"></script> 
        <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


    </head>

    <body>
        <canvas id = "canvas" width = "600" height = "400"></canvas>
        <!--<script src = "js/scriptname.js"></script>-->
    </body>

</html>

..这是我的server.js:

 var express = require('express')
    app     = express() 
    server  = require('http').createServer(app)
    io      = require('socket.io').listen(server)

var positions   = []
var datas       = []
var ids         = []


server.listen(3000)

server.listen(process.env.PORT || 3000, function(){
  console.log('listening on', server.address().port);
});

console.log("server running...")

app.use(express.static("public"))

app.get('/',function(req,res){

    res.sendFile(__dirname + '/index.html')

})



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

    console.log(ids.length + ": " + socket.id)  

    ids.push(socket.id)

    socket.on("disconnect",function(){

        for(i = 0; i < positions.length; i++){

            if(ids[i] == socket.id){

                positions.splice(i,1)
                ids.splice(i,1)

            }

        }
    })


})

这是package.json:

 {

  "name": "projectname",
  "version": "3.10.9",
  "private": "true",
  "dependencies": {
    "socket.io":"1.7.2",
    "express": "4.14.0"
  }

}

我希望你能帮我找到错误(如果我在命令提示符下运行服务器,代码可以在localhost上运行)

0 个答案:

没有答案