在Socket.io中获取SSL协议错误:

时间:2015-05-04 06:42:32

标签: angularjs node.js sockets ssl

我在我的应用程序中使用socket.io。当我没有ssl证书工作时,它工作正常。我是nodejs的新手,我不知道如何添加ssl证书。我正在使用angularjs作为前端,使用nodejs作为后端。 socket.io调用不起作用,我收到ssl协议错误。请帮助我,我做错了什么?

我的angularjs代码

var socket = io.connect('https://localhost:3001', {
      'reconnect': true,
      'reconnection delay': 500,
       'secure' : true
    });

我的nodejs代码

var fs = require('fs');
var PeerSync = require('./lib/PeerSync');
var HistoricSync = require('./lib/HistoricSync');

var http = require('http');
var https = require('https');
var express = require('express');
var program = require('commander');

var config = require('./config/config');
var logger = require('./lib/logger').logger;
program
  .version(config.version);
// setup headers
require('./config/headers')(expressApp);

// setup http/https base server
var server;
if (config.enableHTTPS) {
  var serverOpts = {};
  serverOpts.key = fs.readFileSync('./etc/test-key.pem');
  serverOpts.cert = fs.readFileSync('./etc/test-cert.pem');
  server = https.createServer(serverOpts, expressApp);
} else {
  server = http.createServer(expressApp);
}

0 个答案:

没有答案