【发布时间】:2016-02-06 10:12:30
【问题描述】:
几天前我通过了我在 https 下的 NodeJs 应用(感谢 let's encrypt)
现在的问题是 socket.io 将不再连接到我的服务器。 这是我的前端代码(在 React 下):
layout.jsx
socketHost: 'https://localhost:9091',
...
this.socket = io(this.socketHost, {secure: true});
...
this.socket.on('update', function(data){ ...
在 https socket.io 工作正常之前(我的意思是代码结构还可以。) 这是我的服务器端代码:
index.js:
var app = express();
app
.use(Session)
.use((req, res, next)=>{
if(req.secure)
next();
else
res.redirect('https://' + req.headers.host + req.url);
})
...
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(conf.mainPort);
httpsServer.listen(conf.httpsPort);
require('./app/socket')(httpsServer, Session, store);
app/socket.js:
...
io = require('socket.io')(conf.socketPort),
ios = require('socket.io-express-session');
...
module.exports = function(app, session){
var module = {};
if(app && session){
io.use(ios(session));
io.on('connection', function(socket){
....
我没有使用store 参数,因为此时它对我来说毫无用处。
现在浏览器中的错误:
GET https://localhost:9091/socket.io/?EIO=3&transport=polling&t=1454751433013-95
net::ERR_CONNECTION_REFUSED
【问题讨论】:
标签: javascript node.js express https socket.io