more flexible websocket configuration (WIP)

This commit is contained in:
ansuz 2016-10-03 19:19:38 +02:00
parent 9fa7da60b9
commit 3dfa19b786
3 changed files with 18 additions and 4 deletions

View File

@ -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,

View File

@ -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',
}) + ');');
});

View File

@ -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);
*/