support different ports for websocket and http

This commit is contained in:
Caleb James DeLisle 2014-11-03 11:13:41 +01:00
parent 8d7c85f287
commit 5ae599fa07
3 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,6 @@
module.exports = {
httpPort: 3000,
websocketPort: 3001,
mongoUri: "mongodb://demo_user:demo_password@ds027769.mongolab.com:27769/demo_database",
mongoCollectionName: 'cryptpad'
};

View file

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

View file

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