AngularJS:聊天与socket.io应用程序通过HTTPS [英] AngularJS: chat app with socket.io over https
问题描述
我运行这个例子聊天应用<一href=\"https://github.com/btford/angular-socket-io-im\">https://github.com/btford/angular-socket-io-im使用socket.io/angular/node做一个基本的IM客户端。
I am running this example chat app https://github.com/btford/angular-socket-io-im that uses socket.io/angular/node to make a basic im client.
不过,我遇到麻烦时,我试图让它工作通过HTTPS。
However I run into trouble when I try to make it work over https.
没有套接字事件被发现在服务器上,所以没有聊天消息发送给客户和用户不能加入客房。我也得到了客户端上的这个错误在 socket.io.js
:
No socket events are caught on the server, so no chat messages are sent to clients and users can't join rooms. I also get this error on the client in socket.io.js
:
Uncaught TypeError: Cannot call method 'onClose' of null
我创建了一个前preSS
HTTPS
服务器侦听端口 8000
并修改了插座定义:
I've created an express
https
server listening on port 8000
and modified the socket definition to :
var socket = io.connect('https://localhost:8000',{secure: true, port:8000});
无论是在 JS / services.js
和 /bower_components/angular-socket-io/socket.js
不太清楚如何去解决这个。在此先感谢!
Not quite sure how to go about fixing this. Thanks in advance!
推荐答案
仅是要作一些修改,使通过HTTPS使用它,虽然这是一个古老的前preSS 2.5的应用程序,你应该考虑寻找到:<一HREF =https://github.com/guille/chat-example.git相对=nofollow> https://github.com/guille/chat-example.git
Only a few changes were required to make it available via https, though this is an old express 2.5 application you should consider looking into: https://github.com/guille/chat-example.git
/**
* Module dependencies.
*/
var fs = require('fs');
var options = {
key:fs.readFileSync('key.pem'),
cert:fs.readFileSync('cert.pem')
};
var express = require('express'),
routes = require('./routes'),
socket = require('./routes/socket.js');
var app = module.exports = express.createServer(options);
// Hook Socket.io into Express
var io = require('socket.io').listen(app);
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options', {
layout: false
});
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
// redirect all others to the index (HTML5 history)
app.get('*', routes.index);
// Socket.io Communication
io.sockets.on('connection', socket);
// Start server
app.listen(8080, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
这篇关于AngularJS:聊天与socket.io应用程序通过HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!