// Create context using SSL for socket.io
var fs = require('fs'),
express = require('express'),
socketio = require('socket.io'),
config = require('./config');
var serverPort = config.port || 8765, // Listen port
secure = config.secure || false; // use HTTPS/SSL
var app = express();
if (secure)
{
var options = {
key: fs.readFileSync(config.secure_key),
cert: fs.readFileSync(config.secure_cert)
};
var server = require('https').createServer(options, app);
} else
{
var server = require('http').createServer(app);
}
server.listen(serverPort, function() {
var addr = server.address();
console.log(' app listening on ' + (secure ? 'https://' : 'http://') + addr.address + ':' + addr.port);
});
var io = socketio(server);
// и так далее для io.listen и прочее
Файл config.json
{
"port": "9876",
"secure": true,
"secure_key" : "./ssl_certificate.key",
"secure_cert" : "./ssl_certificate.crt"
}