src/server/controllers.js
function callEntityMethod(req, res, next) {
  var payload = req.payload;
  var method = req.serversideMethod;

  if (req.hasCallback) {

    debug('Transforming callback function');
    payload[req.clientCallbackIndex] = function(err) {
      if (err) {
        return next(err);
      }

      var values = Array.prototype.slice.call(arguments).slice(1);

      debug('Callback function called. Values are:', values);

      res.entityResponse = values;

      next();
    };
  }

  debug('Calling ' + req.path + ' with arguments:', payload);

  var context = {
    req: req,
    xhr: true,
    setCookie: res.cookie.bind(res),
    clearCookie: res.clearCookie.bind(res)
  };

  var ret;

  // Calls the requested serverside method.
  // Applies the payload, and provides a context for validation purposes.
  // Caches errors in the method's scope, and sends it to the next error handler.
  try {
    ret = method.apply(context, payload);
  } catch(err) {
    return next(err);
  }

  if (util.isPromise(ret)) {
    ret.then(function(resolved) {
      res.entityResponse = [resolved];
      next();
    })
    .catch(function(err) {
      next(err);
    });
  }

  // If the request is not expecting the response from the entity,
  // send a generic 'Ok' response.
  else if (!req.hasCallback) {
    res.entityResponse = [ret];
    debug('Not asynchronous. Returning value: ', res.entityResponse);
    next();
  }
}
function callEntityMethod(req, res, next) {
  var payload = req.payload;
  var method = req.serversideMethod;

  if (req.hasCallback) {

    debug('Transforming callback function');
    payload[req.clientCallbackIndex] = function(err) {
      if (err) {
        return next(err);
      }

      var values = Array.prototype.slice.call(arguments).slice(1);

      debug('Callback function called. Values are:', values);

      res.entityResponse = values;

      next();
    };
  }

  debug('Calling ' + req.path + ' with arguments:', payload);

  var context = {
    req: req,
    xhr: true,
    setCookie: res.cookie.bind(res),
    clearCookie: res.clearCookie.bind(res)
  };

  var ret;

  // Calls the requested serverside method.
  // Applies the payload, and provides a context for validation purposes.
  // Caches errors in the method's scope, and sends it to the next error handler.
  try {
    ret = method.apply(context, payload);
  } catch(err) {
    return next(err);
  }

  if (util.isPromise(ret)) {
    ret.then(function(resolved) {
      res.entityResponse = [resolved];
      next();
    })
    .catch(function(err) {
      next(err);
    });
  }

  // If the request is not expecting the response from the entity,
  // send a generic 'Ok' response.
  else if (!req.hasCallback) {
    res.entityResponse = [ret];
    debug('Not asynchronous. Returning value: ', res.entityResponse);
    next();
  }
}
function callEntityMethod ( req , res , next ) { var payload = req . payload ; var method = req . serversideMethod ; if ( req . hasCallback ) { debug ( 'Transforming callback function' ) ; payload [ req . clientCallbackIndex ] = function ( err ) { if ( err ) { return next ( err ) ; } var values = Array . prototype . slice . call ( arguments ) . slice ( 1 ) ; debug ( 'Callback function called. Values are:' , values ) ; res . entityResponse = values ; next ( ) ; } ; } debug ( 'Calling ' + req . path + ' with arguments:' , payload ) ; var context = { req : req , xhr : true , setCookie : res . cookie . bind ( res ) , clearCookie : res . clearCookie . bind ( res ) } ; var ret ; // Calls the requested serverside method. // Applies the payload, and provides a context for validation purposes. // Caches errors in the method's scope, and sends it to the next error handler. try { ret = method . apply ( context , payload ) ; } catch ( err ) { return next ( err ) ; } if ( util . isPromise ( ret ) ) { ret . then ( function ( resolved ) { res . entityResponse = [ resolved ] ; next ( ) ; } ) . catch ( function ( err ) { next ( err ) ; } ) ; } // If the request is not expecting the response from the entity, // send a generic 'Ok' response. else if ( ! req . hasCallback ) { res . entityResponse = [ ret ] ; debug ( 'Not asynchronous. Returning value: ' , res . entityResponse ) ; next ( ) ; } }
Calls the server-side entity, and returns the results to the client
Calls the server - side entity and returns the results to the client