From 5ae599fa07e11b0465e7f593c32b056513ce4c50 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Mon, 3 Nov 2014 11:13:41 +0100 Subject: [PATCH] support different ports for websocket and http --- config.js.dist | 1 + server.js | 16 +++++++++++++++- www/main.js | 7 ++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/config.js.dist b/config.js.dist index b19d72d39..0f7caeea3 100644 --- a/config.js.dist +++ b/config.js.dist @@ -1,5 +1,6 @@ module.exports = { httpPort: 3000, + websocketPort: 3001, mongoUri: "mongodb://demo_user:demo_password@ds027769.mongolab.com:27769/demo_database", mongoCollectionName: 'cryptpad' }; diff --git a/server.js b/server.js index 537ae5f03..22a0cb872 100644 --- a/server.js +++ b/server.js @@ -5,15 +5,29 @@ var ChainPadSrv = require('./ChainPadSrv'); var Storage = require('./Storage'); var config = require('./config'); +config.websocketPort = config.websocketPort || config.httpPort; var app = Express(); app.use(Express.static(__dirname + '/www')); +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({ + websocketURL:'ws://' + host + ':' + config.websocketPort + '/cryptpad_websocket' + }) + ');'); +}); + var httpServer = Http.createServer(app); httpServer.listen(config.httpPort); console.log('listening on port ' + config.httpPort); -var wsSrv = new WebSocketServer({server: httpServer}); +var wsConfig = { server: httpServer }; +if (config.websocketPort !== config.httpPort) { + wsConfig = { port: config.websocketPort }; +} + +var wsSrv = new WebSocketServer(wsConfig); Storage.create(config, function (store) { console.log('DB connected'); ChainPadSrv.create(wsSrv, store); diff --git a/www/main.js b/www/main.js index fd9e0ac2d..6df37ad74 100644 --- a/www/main.js +++ b/www/main.js @@ -1,9 +1,10 @@ define([ + 'api/config?cb=' + Math.random().toString(16).substring(2), 'realtime-wysiwyg', 'bower/jquery/dist/jquery.min', 'bower/ckeditor/ckeditor', - 'bower/tweetnacl/nacl-fast.min' -], function (RTWysiwyg) { + 'bower/tweetnacl/nacl-fast.min', +], function (Config, RTWysiwyg) { var Ckeditor = window.CKEDITOR; var Nacl = window.nacl; var $ = jQuery; @@ -56,7 +57,7 @@ define([ ifr.contentDocument.body.innerHTML = INITIAL_STATE; var rtw = - RTWysiwyg.start(window.location.href.replace(/#.*$/, '').replace(/^http/, 'ws'), + RTWysiwyg.start(Config.websocketURL, userName(), {}, Nacl.util.encodeBase64(key.lookupKey).substring(0,10),