From 3dfa19b786afb81c801e5b6615a6d6f920f613f0 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 3 Oct 2016 19:19:38 +0200 Subject: [PATCH 1/3] more flexible websocket configuration (WIP) --- NetfluxWebsocketSrv.js | 2 +- server.js | 3 +-- www/common/cryptpad-common.js | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/NetfluxWebsocketSrv.js b/NetfluxWebsocketSrv.js index a96e41f2d..02a8f8b19 100644 --- a/NetfluxWebsocketSrv.js +++ b/NetfluxWebsocketSrv.js @@ -277,7 +277,7 @@ let run = module.exports.run = function (storage, socketServer, config) { }); }, 5000); socketServer.on('connection', function(socket) { - if(socket.upgradeReq.url !== '/cryptpad_websocket') { return; } + if(socket.upgradeReq.url !== (config.websocketPath || '/cryptpad_websocket')) { return; } let conn = socket.upgradeReq.connection; let user = { addr: conn.remoteAddress + '|' + conn.remotePort, diff --git a/server.js b/server.js index c490698b3..120ae04e5 100644 --- a/server.js +++ b/server.js @@ -56,10 +56,9 @@ app.get('/api/config', function(req, res){ var host = req.headers.host.replace(/\:[0-9]+/, ''); res.setHeader('Content-Type', 'text/javascript'); res.send('define(' + JSON.stringify({ + websocketPath: config.websocketPath, websocketURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + config.websocketPort + '/cryptpad_websocket', - webrtcURL:'ws' + ((httpsOpts) ? 's' : '') + '://' + host + ':' + - config.websocketPort + '/cryptpad_webrtc', }) + ');'); }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index be31e9f5e..f0e0c5bf4 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1,4 +1,5 @@ define([ + '/api/config?cb=' + Math.random().toString(16).slice(2), '/customize/messages.js', '/customize/store.js', '/bower_components/chainpad-crypto/crypto.js', @@ -8,7 +9,7 @@ define([ '/customize/user.js', '/bower_components/jquery/dist/jquery.min.js', -], function (Messages, Store, Crypto, Alertify, Spinner, User) { +], function (Config, Messages, Store, Crypto, Alertify, Spinner, User) { /* This file exposes functionality which is specific to Cryptpad, but not to any particular pad type. This includes functions for committing metadata about pads to your local storage for future use and improved usability. @@ -36,6 +37,20 @@ define([ throw new Error("Store is not ready!"); }; + var getWebsocketURL = common.getWebsocketURL = function () { + if (!Config.websocketPath) { return Config.websocketURL; } + var path = Config.websocketPath; + if (/^ws{1,2}:\/\//.test(path)) { return path; } + + var protocol = window.location.protocol.replace(/http/, 'ws'); + var host = window.location.host; + var url = protocol + '//' + host + path; + + console.log(url); + + return url; + }; + /* * cb(err, proxy); */ From 0ece2cf6a1e35105b274f8726264bba6db0c946a Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 3 Oct 2016 19:28:14 +0200 Subject: [PATCH 2/3] add to default configuration and comment --- config.js.dist | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/config.js.dist b/config.js.dist index e88b06b0a..c75748508 100644 --- a/config.js.dist +++ b/config.js.dist @@ -9,8 +9,22 @@ module.exports = { // the port on which your httpd will listen httpPort: 3000, - // the port used for websockets - websocketPort: 3000, + + /* your server's websocket url is configurable + (default: '/cryptpad_websocket') + + websocketPath can be relative, of the form '/path/to/websocket' + or absolute, specifying a particular URL + + 'wss://cryptpad.fr:3000/cryptpad_websocket' + */ + websocketPath: '/cryptpad_websocket', + + /* it is assumed that your websocket will bind to the same port as http + you can override this behaviour by supplying a number via websocketPort + */ + //websocketPort: 3000, + /* Cryptpad can log activity to stdout * This may be useful for debugging From 5e761942625c783e51be9e99648287585860a951 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 3 Oct 2016 19:28:36 +0200 Subject: [PATCH 3/3] use new config api --- www/pad/main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/www/pad/main.js b/www/pad/main.js index 18274079f..6eee27d50 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -1,6 +1,5 @@ require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } }); define([ - '/api/config?cb=' + Math.random().toString(16).substring(2), '/customize/messages.js?app=pad', '/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-netflux/chainpad-netflux.js', @@ -18,7 +17,7 @@ define([ '/bower_components/diff-dom/diffDOM.js', '/bower_components/jquery/dist/jquery.min.js', '/customize/pad.js' -], function (Config, Messages, Crypto, realtimeInput, Hyperjson, +], function (Messages, Crypto, realtimeInput, Hyperjson, Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher, Cryptpad, Visible, Notify) { var $ = window.jQuery; @@ -323,7 +322,7 @@ define([ initialState: stringifyDOM(inner) || '{}', // the websocket URL - websocketURL: Config.websocketURL, + websocketURL: Cryptpad.getWebsocketURL(), // the channel we will communicate over channel: secret.channel,