From 95f1992e4d96e1f9c56d5640246432c334f89ec1 Mon Sep 17 00:00:00 2001 From: Andrew Liu Date: Wed, 24 Aug 2011 21:59:50 +0800 Subject: [PATCH] basic support for cloudfoundry. Add - Entry point server.js - Load port and mysql configuraion from env variable - Tunable polling duration --- node/server.js | 2 ++ node/utils/Settings.js | 33 +++++++++++++++++++++++++++++++++ server.js | 5 +++++ settings.json.template | 5 ++++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 server.js diff --git a/node/server.js b/node/server.js index 944e73703..e302ea98e 100644 --- a/node/server.js +++ b/node/server.js @@ -419,6 +419,8 @@ async.waterfall([ //this is only a workaround to ensure it works with all browers behind a proxy //we should remove this when the new socket.io version is more stable io.set('transports', ['xhr-polling']); + + io.set('polling duration', settings.pollingDuration) var socketIOLogger = log4js.getLogger("socket.io"); io.set('logger', { diff --git a/node/utils/Settings.js b/node/utils/Settings.js index 1d855a53d..366e84d24 100644 --- a/node/utils/Settings.js +++ b/node/utils/Settings.js @@ -57,6 +57,11 @@ exports.abiword = null; */ exports.loglevel = "INFO"; +/** + * xhr-polling duration + */ +exports.pollingDuration = 20; + //read the settings sync var settingsStr = fs.readFileSync("../settings.json").toString(); @@ -97,3 +102,31 @@ for(var i in settings) console.warn("This setting doesn't exist or it was removed"); } } + +// If deployed in CloudFoundry +if(process.env.VCAP_APP_PORT) { + exports.port = process.env.VCAP_APP_PORT +} + + +// use mysql if provided. +var vcap_services = process.env.VCAP_SERVICES; + +if(vcap_services) { + var svcs = JSON.parse(vcap_services) + for(var key in svcs ) { + var svc = svcs[key] + console.log("service:" + svc) + if( key.match(/^mysql/) ) { + exports.dbType= "mysql"; + var cred = svc[0].credentials + exports.dbSettings = { + "user" : cred.user , + "host" : cred.host , + "password" : cred.password , + "database" : cred.name , + }; + } + console.debug("database setup:" + console.dir(exports.dbSettings)) + } +} diff --git a/server.js b/server.js new file mode 100644 index 000000000..f8a66b227 --- /dev/null +++ b/server.js @@ -0,0 +1,5 @@ +// Entry point for etherpad running on cloudfoundry +var path = require('path') +process.chdir( path.join( process.cwd(), 'node')) + +var s = require("./node/server") diff --git a/settings.json.template b/settings.json.template index a7afaecc9..d8d2277d5 100644 --- a/settings.json.template +++ b/settings.json.template @@ -37,5 +37,8 @@ "abiword" : null, /* The log level we are using, can be: DEBUG, INFO, WARN, ERROR */ - "loglevel": "INFO" + "loglevel": "INFO", + + /* The xhr-polling duration, default value is 20. */ + "pollingDuration" : 20 }