你能指点我为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);
},
答案 0 :(得分:8)
解决方案是,对于浏览器中的客户端,我忘记更改:
var client = deepstream('127.0.0.1:6020');
为:
var client = deepstream('wss://127.0.0.1:6020');
有一个简单明显的答案。 : - )
答案 1 :(得分:2)
添加一个简单的代码来演示这一点。
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;