3

您能否指点我为 Express 和 Deepstream 配置 SSL 的 Deepstream 设置?

在尝试配置 https 和 wss 后,我主要看到以下错误。另外,我使用的是自签名证书。

混合内容:“ https://127.0.0.1:8082/ ”处的页面通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“ http://127.0.0.1:6020/engine.io/?EIO=3&transport=polling '。此请求已被阻止;内容必须通过 HTTPS 提供。

initializeKeys : function() {
    this.ssl = {};
    this.ssl.cert = fs.readFileSync('./keys/cert.pem', 'utf8');
    this.ssl.key = fs.readFileSync('./keys/key.pem', 'utf8');
},

initializeSecureWebServer: function() {
    var fs = require('fs');
    var https = require('https');
    var credentials = {key: this.ssl.key, cert: this.ssl.cert};
    var express = require('express');
    var app = express();
    app.use('/', express.static(__dirname + '/../client'));
    app.use('/shell', express.static(__dirname + '/../shell'));
    var server = https.createServer(credentials, app);
    server.listen(8082);
},

initializeDeepstreamServer: function() {
    this.server = new DeepstreamServer();
    this.server.set('host', '127.0.0.1');
    this.server.set('port', 6020);
    this.server.set('sslCert', this.ssl.cert);
    this.server.set('sslKey', this.ssl.key);
},
4

2 回答 2

9

解决方案是我忘记更改浏览器中的客户端:

var client = deepstream('127.0.0.1:6020');

至:

var client = deepstream('wss://127.0.0.1:6020');

有一个简单明显的答案。:-)

于 2015-07-31T13:22:45.457 回答
4

添加一个简单的代码来演示这一点。

const ds = require('deepstream.io-client-js');

const client = ds('wss://127.0.0.1:6020', {
  subscriptionTimeout: 500000,
}).login();

client.on('error', (msg, event, topic) => {
  console.error(`[${event}][${topic}]  Deepstream Error: ${msg}`);
});

// Client A
client.event.subscribe('dp/channel', data => {
  // handle published data
console.log(data);
})

// Client B
client.event.emit('dp/channel', { some: 'data1' });
module.exports = client;
于 2019-04-26T11:07:59.063 回答