节点服务器不使用SSL

时间:2016-08-17 03:28:08

标签: node.js laravel ssl socket.io

我在名为 server.js

的节点服务器代码上
var env = require('dotenv').config({path: '../.env'});
var fs = require("fs");
var options = {
  key: fs.readFileSync(env.APP_SSL_PATH + 'server.key').toString(),
  cert: fs.readFileSync(env.APP_SSL_PATH + 'server.crt').toString()
};

var app = require('express')();
var http = require('https');
var server = http.createServer(options, app);
var io = require('socket.io')(server);
var redis = require('redis');


// Check if server is listening on its port 
server.listen(env.APP_NODE_PORT, function() {
  console.log('Listening on your port');

  io.on('connection', function (socket) {

    console.log("new client connected");
    var redisClient = redis.createClient();

    redisClient.subscribe('notification-channel', function(err, count) {
    });

    redisClient.on("message", function(channel, message) {
      console.log( " message= "+ message + " channel = " + channel);
      socket.emit(channel, message);
    });

    socket.on('disconnect', function() {
      redisClient.quit();
    });

  });

});

使用 http 它工作正常但是当我在 https 上添加SSL证书时,代码已经不能正常工作并且它不会引发任何错误。我通过

运行节点server.js
node server.js > stdout.txt 2> stderr.txt

stderr.txt 文件中没有显示错误日志。请帮我解决这个问题。在控制台上 聆听您的端口 只会记录它不会继续并记录 新客户端连接

这是我的客户端代码:

<script>
var socket = io.connect('{{ env("APP_URL") }}:8890');
socket.on('notification-channel', function (data) {
  var header_count_elem = $('#menubar #header-messages-count');

  var count = header_count_elem.text();

  if (data != 'no-sound') {
    $.get('/notification/notif-alerts', function(response) {
      header_count_elem.text((response.count == '0') ? '' : response.count);

      if (data != 'no-sound') {
        if (count != response.count) {
           var sound = '<audio id="audioplayer" autoplay=true volume=1>' +
                '<source src="{{ url('assets/themes/cpanel/alarms/notification_sound.mp3') }}" type="audio/mpeg">' +
                '<source src="{{ url('assets/themes/cpanel/alarms/notification_sound.ogg')}}" type="audio/ogg">' +
                '</audio>';

          $('body').append(sound);
        }

      }

    });
  }

});

0 个答案:

没有答案