generators/app/templates/server/lib/responses/index.js
function sendData(data, options) {
  // jshint validthis: true
  var req = this.req;
  var res = this.res;

  // headers already sent, nothing to do here
  if (res.headersSent) {
    return;
  }

  // If appropriate, serve data as JSON
  if (req.xhr || req.accepts('application/json')) {
    return res.json(data);
  }

  // if a template string is given as the options param
  // use it to render a view
  var viewFilePath = (typeof options === 'string') ? options : options.view;

  // try to render the given template, fall back to json
  // if an error occurs while rendering the view file
  if (viewFilePath && req.accepts('html')) {
    res.render(viewFilePath, data, function (err, result) {
      if (err) {
        return res.json(data);
      }
      return res.send(result);
    });
  }

  return res.json(data);
}
function sendData(data, options) {
  // jshint validthis: true
  var req = this.req;
  var res = this.res;

  // headers already sent, nothing to do here
  if (res.headersSent) {
    return;
  }

  // If appropriate, serve data as JSON
  if (req.xhr || req.accepts('application/json')) {
    return res.json(data);
  }

  // if a template string is given as the options param
  // use it to render a view
  var viewFilePath = (typeof options === 'string') ? options : options.view;

  // try to render the given template, fall back to json
  // if an error occurs while rendering the view file
  if (viewFilePath && req.accepts('html')) {
    res.render(viewFilePath, data, function (err, result) {
      if (err) {
        return res.json(data);
      }
      return res.send(result);
    });
  }

  return res.json(data);
}
function sendData ( data , options ) { // jshint validthis: true var req = this . req ; var res = this . res ; // headers already sent, nothing to do here if ( res . headersSent ) { return ; } // If appropriate, serve data as JSON if ( req . xhr || req . accepts ( 'application/json' ) ) { return res . json ( data ) ; } // if a template string is given as the options param // use it to render a view var viewFilePath = ( typeof options === 'string' ) ? options : options . view ; // try to render the given template, fall back to json // if an error occurs while rendering the view file if ( viewFilePath && req . accepts ( 'html' ) ) { res . render ( viewFilePath , data , function ( err , result ) { if ( err ) { return res . json ( data ) ; } return res . send ( result ) ; } ) ; } return res . json ( data ) ; }
Default response output handler
@param {mixed} data - The data that should be send to the client
@param {Object|String} options - Response configuration object or view template name
@return A Response with the given status set, a rendered view if a view template has
been provided in the options paramter.
Default response output handler