js-adapters/ballroom.js in rhoconnect-4.0.0 vs js-adapters/ballroom.js in rhoconnect-4.0.1
- old
+ new
@@ -2,24 +2,28 @@
fs = require('fs'),
util = require('util'),
EventEmitter = require('events').EventEmitter,
registerEE = new EventEmitter(),
routes = require('./router'),
- client_sub = redis.createClient(),
- client_pub = redis.createClient(),
- pub_channel = process.argv[2] + "RedisPUB",
+ redis_url = require('url').parse(process.env.REDIS_URL),
+ client_sub = redis.createClient(redis_url.port, redis_url.hostname),
+ client_pub = redis.createClient(redis_url.port, redis_url.hostname),
+ pub_channel = process.argv[2] + "-RedisPUB",
rcHelpers = require('./rhoconnect_helpers');
+if(redis_url.auth) {
+ client_sub.auth(redis_url.auth.split(":")[1]);
+ client_pub.auth(redis_url.auth.split(":")[1]);
+}
+
//define global hash functions to store callbacks, routes
rhoconnectCallbacks = {};
registeredRoutes = {};
registeredControllers = {};
registeredModels = {};
var _c_name = null;
var _m_name = null;
-//TODO: Don't have test-specific code here
-var prefixDir = '/spec/apps/rhotestapp';
//TODO: This has to be changed in the future
// The only reason for this - on Windows Node.js
// dies and leaves hanging opened sockets
// Proper way: have a global domain as a safety valve
@@ -110,19 +114,23 @@
};
var register = function(){
var controller_dir = "";
var model_dir = "";
+ var predefined_model_dir = "";
+ var predefined_controller_dir = "";
try{
if(process.argv[3] == 'test' ){
- controller_dir = process.cwd() + prefixDir + "/controllers/js/";
- model_dir = process.cwd() + prefixDir + "/models/js/";
+ controller_dir = process.argv[4] + "/controllers/js/";
+ model_dir = process.argv[4] + "/models/js/";
}
else{
controller_dir = process.cwd() + "/controllers/js/";
model_dir = process.cwd() + "/models/js/";
}
+ predefined_controller_dir = __dirname + "/../lib/rhoconnect/predefined_adapters/controllers/js/";
+ predefined_model_dir = __dirname + "/../lib/rhoconnect/predefined_adapters/models/js/";
if(fs.existsSync(model_dir)){
var modelFiles = fs.readdirSync(model_dir);
modelFiles.forEach(function(file){
//console.error("requiring model file: " + file);
var model = require(model_dir + file);
@@ -136,10 +144,27 @@
//console.error("requiring controller file: " + file);
require(controller_dir + file);
_c_name = null;
});
}
+ if(fs.existsSync(predefined_model_dir)){
+ var modelFiles = fs.readdirSync(predefined_model_dir);
+ modelFiles.forEach(function(file){
+ //console.log("requiring model file: " + predefined_model_dir + file);
+ var model = require(predefined_model_dir + file);
+ var functions = Object.keys(model);
+ mapModelFunctions(file.split(".")[0],functions);
+ });
+ }
+ if(fs.existsSync(predefined_controller_dir)){
+ var controllerFiles = fs.readdirSync(predefined_controller_dir);
+ controllerFiles.forEach(function(file){
+ //console.log("requiring controller file: " + predefined_controller_dir + file);
+ require(predefined_controller_dir + file);
+ _c_name = null;
+ });
+ }
}
catch(e){
console.error("Error loading JavaScript files.");
throw(e);
}
@@ -199,11 +224,13 @@
}
}
function loadModel(name) {
var prefix = process.cwd();
- if(process.argv[3] === 'test') {
- prefix = prefix + prefixDir;
+ if(name.match(/rho_internal/g) !== null){
+ prefix = __dirname + "/../lib/rhoconnect/predefined_adapters";
+ } else if(process.argv[3] === 'test') {
+ prefix = process.argv[4];
}
return require(prefix + "/models/js/" + name);
}
exports.controllerName = controllerName;
\ No newline at end of file