From 6cf86d0704ac061c11ec4eec12d3c1a5eb425338 Mon Sep 17 00:00:00 2001 From: skey Date: Fri, 26 Aug 2016 19:52:14 +0200 Subject: [PATCH 1/3] allow to use SSL --- src/echo-server.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/echo-server.ts b/src/echo-server.ts index 88825e3f..4f388830 100644 --- a/src/echo-server.ts +++ b/src/echo-server.ts @@ -2,6 +2,7 @@ let _ = require('lodash'); let io = require('socket.io') let Redis = require('ioredis') let request = require('request') +let https = require('https'); /** * Echo server class. @@ -80,18 +81,48 @@ export class EchoServer { */ run(options: any): void { this.options = _.merge(this._options, options); + this.loadSecureMode(); + this.initializeSocketIo(); this.startSocketIoServer(); this.redisPubSub(); this.log("Servering at " + this.options.host + ":" + this.options.port); } + /** + * Load SSL 'key' & 'cert' files if https is enabled + * + * @return {void} + */ + loadSecureMode() { + if (!this.options.https) return; + + _.assignIn(this.options, { + key: fs.readFileSync(this.options.ssl_key_path), + cert: fs.readFileSync(this.options.ssl_cert_path) + }); + } + + /** + * Initialize socket.io variable + */ + initializeSocketIo() { + + if (!this.options.https) { + this._io = io(this.options.port); + return; + } + + let _https = https.createServer(this.options).listen(this.options.port); + + this._io = io(_https); + } + /** * Start the Socket.io server. * * @return {void} */ startSocketIoServer(): void { - this._io = io(this.options.port); this._io.on('connection', socket => { this.onSubscribe(socket); this.onUnsubscribe(socket); From b08459eea1002a1940c2b2b8098b08d7e3516124 Mon Sep 17 00:00:00 2001 From: skey Date: Fri, 26 Aug 2016 19:54:53 +0200 Subject: [PATCH 2/3] show SSL config in documentation --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8f220fa7..1ad55e17 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ echo.run(options); | `authPath` | `/broadcasting/auth` | The route that authenticates private channels | | `host` | `http://localhost` | The host of the socket.io server | | `port` | `6001` | The port that the socket.io server should run on | +| `https` | `boolean` | Boolean that allows to use SSL | ## Client Side Configuration From c4cff27397d545d50801b4dd3af83224944cc0b3 Mon Sep 17 00:00:00 2001 From: skey Date: Fri, 26 Aug 2016 19:57:04 +0200 Subject: [PATCH 3/3] show sssl key & cert variables --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ad55e17..78b347af 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ echo.run(options); | `host` | `http://localhost` | The host of the socket.io server | | `port` | `6001` | The port that the socket.io server should run on | | `https` | `boolean` | Boolean that allows to use SSL | - +| `ssl_key_path` | `string` | The path to your client ssl key | +| `ssl_cert_path` | `string` | The path to your client ssl certificate | ## Client Side Configuration