Sha256: f216c80938efd6a81a918ed128feed37bd078d67754b172c6a13bae53331ac0b

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

var Response = require('./response');
var Request = require('./request');

var router = function(json){
  switch(json['route']){
    case 'request':
      try {
        var request = new Request();
        var response = new Response();

        request.params = json['args'];
        request.header = {'request_id':json['request_id'],'route':json['route']};
        request.model = json['model'];
        response.header = {'request_id':json['request_id'],'route':'response'};

        //if calling model function directly load file first
        if(json['klss'] !== undefined){
          if(process.argv[3] == 'test' ){
            var model_dir = process.cwd() + "/spec/apps/rhotestapp/models/js/";
          }
          else{
            var model_dir = process.cwd() + "/models/js/";
          }
          //console.error("path is: ******* " + model_dir + json['klss'] + '.js');
          var mod = require(model_dir + json['klss'] + '.js');
          mod[ json['function']](response);
        }
        else{
          //console.error("reg routes are: " + registeredRoutes[json['url']]);
          registeredRoutes[json['url']](request,response);
        }
        break;
      }
      catch(e){
        console.error("Node.js error caught: "+ e);
        console.error("Backtrace: " + e.stack);
        response.exception = {"error": e};
        response.send(null);
      }
      break;
    case 'response':
      //console.error("result callback is: " + json['callback'])
      var cback = json['callback'];
      json['callback'] = undefined;
      var response = new Response();
      response.header = {'request_id':json['request_id'],'route':'response'};
      response.result = json['result'];

      rhoconnectCallbacks[cback](response);
      delete rhoconnectCallbacks[cback];
      break;
    case 'deregister':
      var br = require('ballroom');
      br.exitNodejs();
      break;
    default : break;
  }
};

exports.router = router;

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rhoconnect-4.0.0.beta.10 js-adapters/router.js