在heroku上的部署应用程序中获取错误

时间:2016-06-24 20:10:32

标签: node.js heroku

这是node.js服务器应用程序:

var WebSocketServer = require('websocket').server;

var express = require('express')

var app = express()

var https = require('https');

var fs = require('fs');

var clients = [];

app.use(express.static(__dirname + "/"))

var options = {

  key: fs.readFileSync('webrtcwwsocket-key.pem'),

  cert: fs.readFileSync('webrtcwwsocket-cert.pem'),

};

var server = https.createServer(options, app);

var port = process.env.PORT || 443

server.listen(port, function() {

  console.log((new Date()) + " Server is listening on port: " + port);

});

// create the server

wsServer = new WebSocketServer({

  httpServer: server

});

function sendCallback(err) {

  if (err) console.error("send() error: " + err);
}

// This callback function is called every time someone

// tries to connect to the WebSocket server

wsServer.on('request', function(request) {

  console.log((new Date()) + ' Connection from origin ' + request.origin +

    '.');

  var connection = request.accept(null, request.origin);

  console.log(' Connection ' + connection.remoteAddress);

  clients.push(connection);

  // This is the most important callback for us, we'll handle

  // all messages from users here.
  connection.on('message', function(message) {
    if (message.type === 'utf8') {
      // process WebSocket message
      console.log((new Date()) + ' Received Message ' +
        message.utf8Data);

      // broadcast message to all connected clients
      clients.forEach(function(outputConnection) {
        if (outputConnection != connection) {
          outputConnection.send(message.utf8Data, sendCallback);
        }
      });
    }
  });
  connection.on('close', function(connection) {
    // close user connection
    console.log((new Date()) + " Peer disconnected.");
  });
});

错误:

2016-06-24T20:02:37.878381+00:00 heroku[web.1]: Starting process with command `: node server.js`

2016-06-24T20:02:41.142647+00:00 heroku[web.1]: Process exited with status 0

2016-06-24T20:02:41.161239+00:00 heroku[web.1]: State changed from starting to crashed

2016-06-24T20:03:09.431123+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=seeittogether.herokuapp.com 

request_id=b541da81-b97e-4123-9487-5ab1943bb183 fwd="110.172.160.202" dyno= connect= service= status=503 bytes=

1 个答案:

答案 0 :(得分:0)

Heroku在HTTPS服务器上运行,因此我们不需要HTTPS服务器。当我将HTTPS更改为HTTP服务器时,它可以工作:)